diff options
author | Andrey Zelenkov <zelenkov@nginx.com> | 2018-01-30 16:17:08 +0300 |
---|---|---|
committer | Andrey Zelenkov <zelenkov@nginx.com> | 2018-01-30 16:17:08 +0300 |
commit | a36babddef203d79dc37736661e1a042df4064f8 (patch) | |
tree | 05e18b70638a7b4cbaa3ccc893aaef413a491b44 /test | |
parent | afa0fd9a71f63a50bb3ff000c41d36f8e4bdb893 (diff) | |
download | unit-a36babddef203d79dc37736661e1a042df4064f8.tar.gz unit-a36babddef203d79dc37736661e1a042df4064f8.tar.bz2 |
Tests: added keep-alive test.
Diffstat (limited to 'test')
-rw-r--r-- | test/test_python_keepalive.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/test/test_python_keepalive.py b/test/test_python_keepalive.py new file mode 100644 index 00000000..518befba --- /dev/null +++ b/test/test_python_keepalive.py @@ -0,0 +1,64 @@ +import unittest +import unit + +class TestUnitApplication(unit.TestUnitControl): + + def setUpClass(): + u = unit.TestUnit() + + u.check_modules('python') + u.check_version('0.4') + + @unittest.expectedFailure + def test_python_keepalive_body(self): + code, name = """ + +def application(environ, start_response): + + content_length = int(environ.get('CONTENT_LENGTH', 0)) + body = bytes(environ['wsgi.input'].read(content_length)) + + start_response('200', [ + ('Content-Type', environ.get('CONTENT_TYPE')), + ('Content-Length', str(len(body))) + ]) + return [body] + +""", 'py_app' + + self.python_application(name, code) + + self.conf({ + "listeners": { + "*:7080": { + "application": "app" + } + }, + "applications": { + "app": { + "type": "python", + "workers": 1, + "path": self.testdir + '/' + name, + "module": "wsgi" + } + } + }) + + (resp, sock) = self.post(headers={ + 'Connection': 'keep-alive', + 'Content-Type': 'text/html', + 'Host': 'localhost' + }, start=True, body='0123456789' * 500) + + self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1') + + resp = self.post(headers={ + 'Connection': 'close', + 'Content-Type': 'text/html', + 'Host': 'localhost' + }, sock=sock, body='0123456789') + + self.assertEqual(resp['body'], '0123456789', 'keep-alive 2') + +if __name__ == '__main__': + unittest.main() |