From efb71121b98c4dfded212e8b6fe33873cfd83376 Mon Sep 17 00:00:00 2001 From: Andrey Zelenkov Date: Mon, 2 Apr 2018 17:03:41 +0300 Subject: Tests: added Python test with iterator context. --- test/python/ctx_iter_atexit/wsgi.py | 23 +++++++++++++++++++++++ test/test_python_application.py | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 test/python/ctx_iter_atexit/wsgi.py (limited to 'test') diff --git a/test/python/ctx_iter_atexit/wsgi.py b/test/python/ctx_iter_atexit/wsgi.py new file mode 100644 index 00000000..d0b33daa --- /dev/null +++ b/test/python/ctx_iter_atexit/wsgi.py @@ -0,0 +1,23 @@ +import atexit + +class application: + def __init__(self, environ, start_response): + self.environ = environ + self.start = start_response + + def __iter__(self): + atexit.register(self._atexit) + + content_length = int(self.environ.get('CONTENT_LENGTH', 0)) + body = bytes(self.environ['wsgi.input'].read(content_length)) + + self.start('200', [ + ('Content-Type', self.environ.get('CONTENT_TYPE')), + ('Content-Length', str(len(body))) + ]) + yield body + + def _atexit(self): + self.start('200', [ + ('Content-Length', '0') + ]) diff --git a/test/test_python_application.py b/test/test_python_application.py index 1a1a8741..0307a8f6 100644 --- a/test/test_python_application.py +++ b/test/test_python_application.py @@ -60,5 +60,28 @@ class TestUnitPythonApplication(unit.TestUnitApplicationPython): self.assertNotIn('Transfer-Encoding', self.get()['headers'], '204 header transfer encoding') + def test_python_application_ctx_iter_atexit(self): + self.skip_alerts.append(r'sendmsg.+failed') + self.load('ctx_iter_atexit') + + resp = self.post(headers={ + 'Connection': 'close', + 'Content-Type': 'text/html', + 'Host': 'localhost' + }, body='0123456789') + + self.assertEqual(resp['status'], 200, 'ctx iter status') + self.assertEqual(resp['body'], '0123456789', 'ctx iter body') + + self.conf({ + "listeners": {}, + "applications": {} + }) + + self.stop() + + self.assertIsNotNone(self.search_in_log(r'RuntimeError'), + 'ctx iter atexit') + if __name__ == '__main__': unittest.main() -- cgit