diff options
author | Andrei Belov <defan@nginx.com> | 2019-11-14 19:29:00 +0300 |
---|---|---|
committer | Andrei Belov <defan@nginx.com> | 2019-11-14 19:29:00 +0300 |
commit | 7630539c44fcb188bba03a65af34e952a81f2f38 (patch) | |
tree | 2c80f0cd315cae8079a39ba98ed89e02b5e1931a /test/python | |
parent | 70c9f18b6e8b25850bce8eb1edba4d100c3e55d2 (diff) | |
parent | 0a27f137de776925a24406cf6961c550824c63a0 (diff) | |
download | unit-7630539c44fcb188bba03a65af34e952a81f2f38.tar.gz unit-7630539c44fcb188bba03a65af34e952a81f2f38.tar.bz2 |
Merged with the default branch.1.13.0-1
Diffstat (limited to 'test/python')
-rw-r--r-- | test/python/delayed/wsgi.py | 25 | ||||
-rw-r--r-- | test/python/errors_write/wsgi.py | 1 | ||||
-rw-r--r-- | test/python/iter_exception/wsgi.py | 45 | ||||
-rw-r--r-- | test/python/log_body/wsgi.py | 9 | ||||
-rw-r--r-- | test/python/threading/wsgi.py | 33 |
5 files changed, 113 insertions, 0 deletions
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 [] 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 [] 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') 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 [] 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 [] |