diff options
Diffstat (limited to 'test')
-rwxr-xr-x | test/node/write_before_write_head/app.js | 1 | ||||
-rw-r--r-- | test/perl/body_io_fake/IOFake.pm | 33 | ||||
-rw-r--r-- | test/perl/body_io_fake/psgi.pl | 11 | ||||
-rw-r--r-- | test/php/query_string/index.php | 4 | ||||
-rw-r--r-- | test/test_configuration.py | 47 | ||||
-rw-r--r-- | test/test_go_application.py | 7 | ||||
-rw-r--r-- | test/test_node_application.py | 11 | ||||
-rw-r--r-- | test/test_perl_application.py | 33 | ||||
-rw-r--r-- | test/test_php_application.py | 27 | ||||
-rw-r--r-- | test/test_python_application.py | 22 | ||||
-rw-r--r-- | test/test_ruby_application.py | 19 | ||||
-rw-r--r-- | test/test_tls.py | 20 | ||||
-rw-r--r-- | test/unit.py | 10 |
13 files changed, 216 insertions, 29 deletions
diff --git a/test/node/write_before_write_head/app.js b/test/node/write_before_write_head/app.js index 9fe3a58d..6e3fb9a9 100755 --- a/test/node/write_before_write_head/app.js +++ b/test/node/write_before_write_head/app.js @@ -3,4 +3,5 @@ require('unit-http').createServer(function (req, res) { res.write('blah'); res.writeHead(200, {'Content-Type': 'text/plain'}); + res.end(); }).listen(7080); diff --git a/test/perl/body_io_fake/IOFake.pm b/test/perl/body_io_fake/IOFake.pm new file mode 100644 index 00000000..d2542aa5 --- /dev/null +++ b/test/perl/body_io_fake/IOFake.pm @@ -0,0 +1,33 @@ +package IOFake; + +sub new { + my $class = shift; + my $errors = shift; + my $self = {}; + + $self->{_count} = 2; + $self->{_errors} = $errors; + + bless $self, $class; + return $self; +} + +sub getline() { + my $self = shift; + + if ($self->{_count} > 0) { + return $self->{_count}--; + } + + $self->{_errors}->print('IOFake getline() $/ is ' . ${ $/ }); + + return; +} + +sub close() { + my $self = shift; + + $self->{_errors}->print('IOFake close() called'); +}; + +1; diff --git a/test/perl/body_io_fake/psgi.pl b/test/perl/body_io_fake/psgi.pl new file mode 100644 index 00000000..6990bfaf --- /dev/null +++ b/test/perl/body_io_fake/psgi.pl @@ -0,0 +1,11 @@ +use File::Basename; +use lib dirname (__FILE__); +use IOFake; + +my $app = sub { + my ($environ) = @_; + + my $io = IOFake->new($environ->{'psgi.errors'}); + + return ['200', [ 'Content-Length' => '2' ], $io]; +}; diff --git a/test/php/query_string/index.php b/test/php/query_string/index.php new file mode 100644 index 00000000..5691324d --- /dev/null +++ b/test/php/query_string/index.php @@ -0,0 +1,4 @@ +<?php +header('Content-Length: 0'); +header('Query-String: ' . $_SERVER['QUERY_STRING']); +?> diff --git a/test/test_configuration.py b/test/test_configuration.py index 02705afe..7f81b86b 100644 --- a/test/test_configuration.py +++ b/test/test_configuration.py @@ -217,5 +217,52 @@ class TestUnitConfiguration(unit.TestUnitControl): } }), 'no port') + @unittest.expectedFailure + def test_json_application_name_large(self): + self.skip_alerts.append(r'epoll_ctl.+failed') + name = "X" * 1024 * 1024 + + self.assertIn('success', self.conf({ + "listeners": { + "*:7080": { + "application": name + } + }, + "applications": { + name: { + "type": "python", + "processes": { "spare": 0 }, + "path": "/app", + "module": "wsgi" + } + } + })) + + @unittest.expectedFailure + def test_json_application_many(self): + self.skip_alerts.extend([ + r'eventfd.+failed', + r'failed to apply new conf' + ]) + apps = 1000 + + conf = { + "applications": + {"app-" + str(a): { + "type": "python", + "processes": { "spare": 0 }, + "path": "/app", + "module": "wsgi" + } for a in range(apps) + }, + "listeners": { + "*:" + str(7080 + a): { + "application": "app-" + str(a) + } for a in range(apps) + } + } + + self.assertIn('success', self.conf(conf)) + if __name__ == '__main__': TestUnitConfiguration.main() diff --git a/test/test_go_application.py b/test/test_go_application.py index fd80bf5b..90785851 100644 --- a/test/test_go_application.py +++ b/test/test_go_application.py @@ -4,12 +4,7 @@ import unit class TestUnitGoApplication(unit.TestUnitApplicationGo): def setUpClass(): - u = unit.TestUnit() - - if u.architecture == '32bit': - raise unittest.SkipTest('Skip Go tests for x86') - - u.check_modules('go') + unit.TestUnit().check_modules('go') def test_go_application_variables(self): self.load('variables') diff --git a/test/test_node_application.py b/test/test_node_application.py index 5dedb5a3..05b518f5 100644 --- a/test/test_node_application.py +++ b/test/test_node_application.py @@ -112,7 +112,6 @@ class TestUnitNodeApplication(unit.TestUnitApplicationNode): self.assertEqual(self.get()['body'], '6\r\nbuffer\r\n0\r\n\r\n', 'write buffer') - @unittest.expectedFailure def test_node_application_write_callback(self): self.load('write_callback') @@ -121,11 +120,10 @@ class TestUnitNodeApplication(unit.TestUnitApplicationNode): self.assertTrue(self.waitforfiles(self.testdir + '/node/callback'), 'write callback') - def test_node_application_write_before_writeHead(self): - self.skip_alerts.append(r'process \d+ exited on signal') + def test_node_application_write_before_write_head(self): self.load('write_before_write_head') - self.get() + self.assertEqual(self.get()['status'], 200, 'write before writeHead') def test_node_application_double_end(self): self.load('double_end') @@ -182,7 +180,6 @@ class TestUnitNodeApplication(unit.TestUnitApplicationNode): self.assertEqual(self.get()['headers']['X-Type'], 'number', 'get header type') - @unittest.expectedFailure def test_node_application_header_name_case(self): self.load('header_name_case') @@ -202,9 +199,7 @@ class TestUnitNodeApplication(unit.TestUnitApplicationNode): self.assertTrue(self.waitforfiles(self.testdir + '/node/callback'), 'promise handler') - @unittest.expectedFailure def test_node_application_promise_handler_write_after_end(self): - self.skip_alerts.append(r'process \d+ exited on signal') self.load('promise_handler') self.assertEqual(self.post(headers={ @@ -249,13 +244,11 @@ class TestUnitNodeApplication(unit.TestUnitApplicationNode): self.assertNotIn('status', self.get(), 'header name valid') - @unittest.expectedFailure def test_node_application_header_value_object(self): self.load('header_value_object') self.assertIn('X-Header', self.get()['headers'], 'header value object') - @unittest.expectedFailure def test_node_application_get_header_names(self): self.load('get_header_names') diff --git a/test/test_perl_application.py b/test/test_perl_application.py index c9cb3f0c..7850e231 100644 --- a/test/test_perl_application.py +++ b/test/test_perl_application.py @@ -55,6 +55,25 @@ class TestUnitPerlApplication(unit.TestUnitApplicationPerl): self.assertEqual(resp['headers']['Query-String'], 'var1=val1&var2=val2', 'Query-String header') + def test_perl_application_query_string_empty(self): + self.load('query_string') + + resp = self.get(url='/?') + + self.assertEqual(resp['status'], 200, 'query string empty status') + self.assertEqual(resp['headers']['Query-String'], '', + 'query string empty') + + @unittest.expectedFailure + def test_perl_application_query_string_absent(self): + self.load('query_string') + + resp = self.get() + + self.assertEqual(resp['status'], 200, 'query string absent status') + self.assertEqual(resp['headers']['Query-String'], '', + 'query string absent') + @unittest.expectedFailure def test_perl_application_server_port(self): self.load('server_port') @@ -166,5 +185,19 @@ class TestUnitPerlApplication(unit.TestUnitApplicationPerl): self.assertEqual(resp['body'], '0123456789', 'keep-alive 2') + @unittest.expectedFailure + def test_perl_body_io_fake(self): + self.load('body_io_fake') + + self.assertEqual(self.get()['body'], '21', 'body io fake') + + self.assertIsNotNone( + self.search_in_log(r'\[error\].+IOFake getline\(\) \$\/ is \d+'), + 'body io fake $/ value') + + self.assertIsNotNone( + self.search_in_log(r'\[error\].+IOFake close\(\) called'), + 'body io fake close') + if __name__ == '__main__': TestUnitPerlApplication.main() diff --git a/test/test_php_application.py b/test/test_php_application.py index e0058d9a..ba9c03b3 100644 --- a/test/test_php_application.py +++ b/test/test_php_application.py @@ -48,6 +48,33 @@ class TestUnitPHPApplication(unit.TestUnitApplicationPHP): }, 'headers') self.assertEqual(resp['body'], body, 'body') + def test_php_application_query_string(self): + self.load('query_string') + + resp = self.get(url='/?var1=val1&var2=val2') + + self.assertEqual(resp['headers']['Query-String'], 'var1=val1&var2=val2', + 'query string') + + def test_php_application_query_string_empty(self): + self.load('query_string') + + resp = self.get(url='/?') + + self.assertEqual(resp['status'], 200, 'query string empty status') + self.assertEqual(resp['headers']['Query-String'], '', + 'query string empty') + + @unittest.expectedFailure + def test_php_application_query_string_absent(self): + self.load('query_string') + + resp = self.get() + + self.assertEqual(resp['status'], 200, 'query string absent status') + self.assertEqual(resp['headers']['Query-String'], '', + 'query string absent') + def test_php_application_phpinfo(self): self.load('phpinfo') diff --git a/test/test_python_application.py b/test/test_python_application.py index 667047bc..b28675f9 100644 --- a/test/test_python_application.py +++ b/test/test_python_application.py @@ -1,3 +1,4 @@ +import time import unittest import unit @@ -53,6 +54,25 @@ class TestUnitPythonApplication(unit.TestUnitApplicationPython): self.assertEqual(resp['headers']['Query-String'], 'var1=val1&var2=val2', 'Query-String header') + def test_python_application_query_string_empty(self): + self.load('query_string') + + resp = self.get(url='/?') + + self.assertEqual(resp['status'], 200, 'query string empty status') + self.assertEqual(resp['headers']['Query-String'], '', + 'query string empty') + + @unittest.expectedFailure + def test_python_application_query_string_absent(self): + self.load('query_string') + + resp = self.get() + + self.assertEqual(resp['status'], 200, 'query string absent status') + self.assertEqual(resp['headers']['Query-String'], '', + 'query string absent') + @unittest.expectedFailure def test_python_application_server_port(self): self.load('server_port') @@ -86,6 +106,8 @@ class TestUnitPythonApplication(unit.TestUnitApplicationPython): self.stop() + time.sleep(0.2) + self.assertIsNotNone(self.search_in_log(r'RuntimeError'), 'ctx iter atexit') diff --git a/test/test_ruby_application.py b/test/test_ruby_application.py index 57ab88cd..b88e043d 100644 --- a/test/test_ruby_application.py +++ b/test/test_ruby_application.py @@ -56,6 +56,25 @@ class TestUnitRubyApplication(unit.TestUnitApplicationRuby): self.assertEqual(resp['headers']['Query-String'], 'var1=val1&var2=val2', 'Query-String header') + def test_ruby_application_query_string_empty(self): + self.load('query_string') + + resp = self.get(url='/?') + + self.assertEqual(resp['status'], 200, 'query string empty status') + self.assertEqual(resp['headers']['Query-String'], '', + 'query string empty') + + @unittest.expectedFailure + def test_ruby_application_query_string_absent(self): + self.load('query_string') + + resp = self.get() + + self.assertEqual(resp['status'], 200, 'query string absent status') + self.assertEqual(resp['headers']['Query-String'], '', + 'query string absent') + @unittest.expectedFailure def test_ruby_application_server_port(self): self.load('server_port') diff --git a/test/test_tls.py b/test/test_tls.py index fa5c9754..dc2f4505 100644 --- a/test/test_tls.py +++ b/test/test_tls.py @@ -306,23 +306,25 @@ basicConstraints = critical,CA:TRUE""" % { self.assertEqual(self.get_ssl()['status'], 200, 'certificate chain intermediate server') + @unittest.expectedFailure def test_tls_reconfigure(self): self.load('empty') self.certificate() - (resp, sock) = self.http(b"""GET / HTTP/1.1 -""", start=True, raw=True, no_recv=True) - - self.add_tls() + (resp, sock) = self.get(headers={ + 'Connection': 'keep-alive', + 'Host': 'localhost' + }, start=True) - resp = self.http(b"""Host: localhost -Connection: close + self.assertEqual(resp['status'], 200, 'initial status') -""", sock=sock, raw=True) + self.add_tls() - self.assertEqual(resp['status'], 200, 'update status') - self.assertEqual(self.get_ssl()['status'], 200, 'update tls status') + self.assertEqual(self.get(sock=sock)['status'], 200, + 'reconfigure status') + self.assertEqual(self.get_ssl()['status'], 200, + 'reconfigure tls status') def test_tls_keepalive(self): self.load('mirror') diff --git a/test/unit.py b/test/unit.py index e88ed684..55b3ce18 100644 --- a/test/unit.py +++ b/test/unit.py @@ -285,7 +285,6 @@ class TestUnitHTTP(TestUnit): port = 7080 if 'port' not in kwargs else kwargs['port'] url = '/' if 'url' not in kwargs else kwargs['url'] http = 'HTTP/1.0' if 'http_10' in kwargs else 'HTTP/1.1' - blocking = False if 'blocking' not in kwargs else kwargs['blocking'] headers = ({ 'Host': 'localhost', @@ -309,6 +308,9 @@ class TestUnitHTTP(TestUnit): if 'sock' not in kwargs: sock = socket.socket(sock_types[sock_type], socket.SOCK_STREAM) + if sock_type == sock_types['ipv4'] or sock_type == sock_types['ipv6']: + sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) + if 'wrapper' in kwargs: sock = kwargs['wrapper'](sock) @@ -319,8 +321,6 @@ class TestUnitHTTP(TestUnit): sock.close() return None - sock.setblocking(blocking) - else: sock = kwargs['sock'] @@ -637,11 +637,11 @@ class TestUnitApplicationTLS(TestUnitApplicationProto): return self.conf(k.read() + c.read(), '/certificates/' + crt) def get_ssl(self, **kwargs): - return self.get(blocking=True, wrapper=self.context.wrap_socket, + return self.get(wrapper=self.context.wrap_socket, **kwargs) def post_ssl(self, **kwargs): - return self.post(blocking=True, wrapper=self.context.wrap_socket, + return self.post(wrapper=self.context.wrap_socket, **kwargs) def get_server_certificate(self, addr=('127.0.0.1', 7080)): |