From 1bece759a3615b97c0a78e204eff23d13bba052d Mon Sep 17 00:00:00 2001 From: Andrey Zelenkov Date: Wed, 23 Oct 2019 16:05:35 +0300 Subject: Tests: added flush() in "errors_write" Python application. --- test/python/errors_write/wsgi.py | 1 + 1 file changed, 1 insertion(+) (limited to 'test/python') diff --git a/test/python/errors_write/wsgi.py b/test/python/errors_write/wsgi.py index b1a9d2ee..148bce9e 100644 --- a/test/python/errors_write/wsgi.py +++ b/test/python/errors_write/wsgi.py @@ -1,5 +1,6 @@ def application(environ, start_response): environ['wsgi.errors'].write('Error in application.') + environ['wsgi.errors'].flush() start_response('200', [('Content-Length', '0')]) return [] -- cgit From 38cfe4cf3d9fd2a4ed0f3949586126a7b8144e8e Mon Sep 17 00:00:00 2001 From: Andrey Zelenkov Date: Wed, 23 Oct 2019 16:59:53 +0300 Subject: Tests: added USR1 signal test for unit.log. --- test/python/log_body/wsgi.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 test/python/log_body/wsgi.py (limited to 'test/python') diff --git a/test/python/log_body/wsgi.py b/test/python/log_body/wsgi.py new file mode 100644 index 00000000..9dcb1b0c --- /dev/null +++ b/test/python/log_body/wsgi.py @@ -0,0 +1,9 @@ +def application(environ, start_response): + content_length = int(environ.get('CONTENT_LENGTH', 0)) + body = bytes(environ['wsgi.input'].read(content_length)) + + environ['wsgi.errors'].write(body) + environ['wsgi.errors'].flush() + + start_response('200', [('Content-Length', '0')]) + return [] -- cgit From 45d75ee2cb33d38f64ca2ac5d871fa0cc2f1bcde Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Wed, 13 Nov 2019 16:51:12 +0300 Subject: Tests: added Python test with threading. --- test/python/threading/wsgi.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 test/python/threading/wsgi.py (limited to 'test/python') diff --git a/test/python/threading/wsgi.py b/test/python/threading/wsgi.py new file mode 100644 index 00000000..adaa2a37 --- /dev/null +++ b/test/python/threading/wsgi.py @@ -0,0 +1,33 @@ +import sys +import time +import threading + + +class Foo(threading.Thread): + num = 10 + + def __init__(self, x): + self.__x = x + threading.Thread.__init__(self) + + def log_index(self, index): + sys.stderr.write( + "(" + str(index) + ") Thread: " + str(self.__x) + "\n" + ) + sys.stderr.flush() + + def run(self): + i = 0 + for _ in range(3): + self.log_index(i) + i += 1 + time.sleep(1) + self.log_index(i) + i += 1 + + +def application(environ, start_response): + Foo(Foo.num).start() + Foo.num += 10 + start_response('200 OK', [('Content-Length', '0')]) + return [] -- cgit From c7726c0eb1157ea90cd0e6eb1d0f29587f2148c0 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Thu, 14 Nov 2019 17:15:29 +0300 Subject: Tests: proxy tests. --- test/python/delayed/wsgi.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 test/python/delayed/wsgi.py (limited to 'test/python') diff --git a/test/python/delayed/wsgi.py b/test/python/delayed/wsgi.py new file mode 100644 index 00000000..d25e2765 --- /dev/null +++ b/test/python/delayed/wsgi.py @@ -0,0 +1,25 @@ +import time + + +def application(environ, start_response): + parts = int(environ.get('HTTP_X_PARTS', 1)) + delay = int(environ.get('HTTP_X_DELAY', 0)) + + content_length = int(environ.get('CONTENT_LENGTH', 0)) + body = bytes(environ['wsgi.input'].read(content_length)) + + write = start_response('200', [('Content-Length', str(len(body)))]) + + if not body: + return [] + + step = int(len(body) / parts) + for i in range(0, len(body), step): + try: + write(body[i : i + step]) + except: + break + + time.sleep(delay) + + return [] -- cgit From 1072c9482998fd698bc400953e0db9fe2c6b75f2 Mon Sep 17 00:00:00 2001 From: Andrei Zeliankou Date: Thu, 14 Nov 2019 18:46:28 +0300 Subject: Tests: Python exception tests. --- test/python/iter_exception/wsgi.py | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 test/python/iter_exception/wsgi.py (limited to 'test/python') diff --git a/test/python/iter_exception/wsgi.py b/test/python/iter_exception/wsgi.py new file mode 100644 index 00000000..66a09af7 --- /dev/null +++ b/test/python/iter_exception/wsgi.py @@ -0,0 +1,45 @@ +class application: + def __init__(self, environ, start_response): + self.environ = environ + self.start = start_response + + self.next = self.__next__ + + def __iter__(self): + self.__i = 0 + self._skip_level = int(self.environ.get('HTTP_X_SKIP', 0)) + self._not_skip_close = int(self.environ.get('HTTP_X_NOT_SKIP_CLOSE', 0)) + self._is_chunked = self.environ.get('HTTP_X_CHUNKED') + + headers = [(('Content-Length', '10'))] + if self._is_chunked is not None: + headers = [] + + if self._skip_level < 1: + raise Exception('first exception') + + write = self.start('200', headers) + + if self._skip_level < 2: + raise Exception('second exception') + + write(b'XXXXX') + + if self._skip_level < 3: + raise Exception('third exception') + + return self + + def __next__(self): + if self._skip_level < 4: + raise Exception('next exception') + + self.__i += 1 + if self.__i > 2: + raise StopIteration + + return b'X' + + def close(self): + if self._not_skip_close == 1: + raise Exception('close exception') -- cgit