Tests: speed up tests.

This commit is contained in:
Andrey Zelenkov
2019-04-09 20:59:35 +03:00
parent 549f0873c2
commit 29b4e4431f
11 changed files with 59 additions and 8 deletions

View File

@@ -4,7 +4,6 @@ def application(environ, start_response):
body = bytes(environ['wsgi.input'].read(content_length))
start_response('200', [
('Content-Type', environ.get('CONTENT_TYPE')),
('Content-Length', str(len(body)))
])
return [body]

View File

@@ -19,6 +19,8 @@ class TestAccessLog(TestApplicationPython):
def test_access_log_keepalive(self):
self.load('mirror')
self.assertEqual(self.get()['status'], 200, 'init')
(resp, sock) = self.post(
headers={
'Host': 'localhost',
@@ -27,6 +29,7 @@ class TestAccessLog(TestApplicationPython):
},
start=True,
body='01234',
read_timeout=1,
)
self.assertIsNotNone(
@@ -174,7 +177,7 @@ Connection: close
def test_access_log_partial(self):
self.load('empty')
self.http(b"""GE""", raw=True)
self.http(b"""GE""", raw=True, no_recv=True)
self.stop()
@@ -185,7 +188,7 @@ Connection: close
def test_access_log_partial_2(self):
self.load('empty')
self.http(b"""GET /\n""", raw=True)
self.http(b"""GET /\n""", raw=True, no_recv=True)
self.stop()
@@ -196,7 +199,7 @@ Connection: close
def test_access_log_partial_3(self):
self.load('empty')
self.http(b"""GET / HTTP/1.1""", raw=True)
self.http(b"""GET / HTTP/1.1""", raw=True, no_recv=True)
self.stop()
@@ -207,7 +210,7 @@ Connection: close
def test_access_log_partial_4(self):
self.load('empty')
resp = self.http(b"""GET / HTTP/1.1\n""", raw=True)
resp = self.http(b"""GET / HTTP/1.1\n""", raw=True, no_recv=True)
self.stop()
@@ -219,7 +222,9 @@ Connection: close
def test_access_log_partial_5(self):
self.load('empty')
self.http(b"""GET / HTTP/1.1\n\n""", raw=True)
self.assertEqual(self.post()['status'], 200, 'init')
self.http(b"""GET / HTTP/1.1\n\n""", raw=True, read_timeout=1)
self.stop()

View File

@@ -88,6 +88,8 @@ class TestGoApplication(TestApplicationGo):
def test_go_keepalive_body(self):
self.load('mirror')
self.assertEqual(self.get()['status'], 200, 'init')
(resp, sock) = self.post(
headers={
'Host': 'localhost',
@@ -96,6 +98,7 @@ class TestGoApplication(TestApplicationGo):
},
start=True,
body='0123456789' * 500,
read_timeout=1,
)
self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1')

View File

@@ -1031,6 +1031,8 @@ class TestJavaApplication(TestApplicationJava):
def test_java_application_keepalive_body(self):
self.load('mirror')
self.assertEqual(self.post()['status'], 200, 'init')
(resp, sock) = self.post(
headers={
'Connection': 'keep-alive',
@@ -1039,6 +1041,7 @@ class TestJavaApplication(TestApplicationJava):
},
start=True,
body='0123456789' * 500,
read_timeout=1,
)
self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1')
@@ -1128,6 +1131,8 @@ class TestJavaApplication(TestApplicationJava):
def test_java_application_get_header_names_empty(self):
self.load('get_header_names')
self.assertEqual(self.get()['status'], 200, 'init')
self.assertNotIn(
'X-Reply-0',
self.get(headers={}, read_timeout=1)['headers'],

View File

@@ -110,6 +110,8 @@ class TestNodeApplication(TestApplicationNode):
def test_node_keepalive_body(self):
self.load('mirror')
self.assertEqual(self.get()['status'], 200, 'init')
(resp, sock) = self.post(
headers={
'Host': 'localhost',
@@ -118,6 +120,7 @@ class TestNodeApplication(TestApplicationNode):
},
start=True,
body='0123456789' * 500,
read_timeout=1,
)
self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1')

View File

@@ -196,6 +196,8 @@ class TestPerlApplication(TestApplicationPerl):
def test_perl_keepalive_body(self):
self.load('variables')
self.assertEqual(self.get()['status'], 200, 'init')
(resp, sock) = self.post(
headers={
'Host': 'localhost',
@@ -204,6 +206,7 @@ class TestPerlApplication(TestApplicationPerl):
},
start=True,
body='0123456789' * 500,
read_timeout=1,
)
self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1')

View File

@@ -116,6 +116,8 @@ class TestPHPApplication(TestApplicationPHP):
def test_php_application_keepalive_body(self):
self.load('mirror')
self.assertEqual(self.get()['status'], 200, 'init')
(resp, sock) = self.post(
headers={
'Host': 'localhost',
@@ -124,6 +126,7 @@ class TestPHPApplication(TestApplicationPHP):
},
start=True,
body='0123456789' * 500,
read_timeout=1,
)
self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1')

View File

@@ -134,6 +134,8 @@ class TestPythonApplication(TestApplicationPython):
def test_python_keepalive_body(self):
self.load('mirror')
self.assertEqual(self.get()['status'], 200, 'init')
(resp, sock) = self.post(
headers={
'Host': 'localhost',
@@ -142,6 +144,7 @@ class TestPythonApplication(TestApplicationPython):
},
start=True,
body='0123456789' * 500,
read_timeout=1,
)
self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1')
@@ -168,6 +171,8 @@ class TestPythonApplication(TestApplicationPython):
)
self.load('mirror')
self.assertEqual(self.get()['status'], 200, 'init')
body = '0123456789'
conns = 3
socks = []
@@ -181,6 +186,7 @@ class TestPythonApplication(TestApplicationPython):
},
start=True,
body=body,
read_timeout=1,
)
self.assertEqual(resp['body'], body, 'keep-alive open')
@@ -202,6 +208,7 @@ class TestPythonApplication(TestApplicationPython):
start=True,
sock=socks[i],
body=body,
read_timeout=1,
)
self.assertEqual(resp['body'], body, 'keep-alive request')
@@ -232,6 +239,8 @@ class TestPythonApplication(TestApplicationPython):
def test_python_keepalive_reconfigure_2(self):
self.load('mirror')
self.assertEqual(self.get()['status'], 200, 'init')
body = '0123456789'
(resp, sock) = self.post(
@@ -242,12 +251,15 @@ class TestPythonApplication(TestApplicationPython):
},
start=True,
body=body,
read_timeout=1,
)
self.assertEqual(resp['body'], body, 'reconfigure 2 keep-alive 1')
self.load('empty')
self.assertEqual(self.get()['status'], 200, 'init')
(resp, sock) = self.post(
headers={
'Host': 'localhost',
@@ -275,11 +287,14 @@ class TestPythonApplication(TestApplicationPython):
def test_python_keepalive_reconfigure_3(self):
self.load('empty')
self.assertEqual(self.get()['status'], 200, 'init')
(resp, sock) = self.http(
b"""GET / HTTP/1.1
""",
start=True,
raw=True,
read_timeout=1,
)
self.assertIn(

View File

@@ -321,6 +321,8 @@ class TestRubyApplication(TestApplicationRuby):
def test_ruby_keepalive_body(self):
self.load('mirror')
self.assertEqual(self.get()['status'], 200, 'init')
(resp, sock) = self.post(
headers={
'Host': 'localhost',
@@ -329,6 +331,7 @@ class TestRubyApplication(TestApplicationRuby):
},
start=True,
body='0123456789' * 500,
read_timeout=1,
)
self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1')

View File

@@ -42,7 +42,6 @@ Connection: close
b"""GET / HTTP/1.1
""",
start=True,
read_timeout=1,
raw=True,
no_recv=True,
)
@@ -54,7 +53,6 @@ Connection: close
""",
start=True,
sock=sock,
read_timeout=1,
raw=True,
no_recv=True,
)
@@ -189,6 +187,8 @@ Connection: close
def test_settings_idle_timeout(self):
self.load('empty')
self.assertEqual(self.get()['status'], 200, 'init')
self.conf({'http': {'idle_timeout': 2}}, 'settings')
(resp, sock) = self.get(

View File

@@ -411,11 +411,14 @@ basicConstraints = critical,CA:TRUE"""
def test_tls_reconfigure(self):
self.load('empty')
self.assertEqual(self.get()['status'], 200, 'init')
self.certificate()
(resp, sock) = self.get(
headers={'Host': 'localhost', 'Connection': 'keep-alive'},
start=True,
read_timeout=1,
)
self.assertEqual(resp['status'], 200, 'initial status')
@@ -432,6 +435,8 @@ basicConstraints = critical,CA:TRUE"""
def test_tls_keepalive(self):
self.load('mirror')
self.assertEqual(self.get()['status'], 200, 'init')
self.certificate()
self.add_tls(application='mirror')
@@ -444,6 +449,7 @@ basicConstraints = critical,CA:TRUE"""
},
start=True,
body='0123456789',
read_timeout=1,
)
self.assertEqual(resp['body'], '0123456789', 'keepalive 1')
@@ -464,6 +470,8 @@ basicConstraints = critical,CA:TRUE"""
def test_tls_keepalive_certificate_remove(self):
self.load('empty')
self.assertEqual(self.get()['status'], 200, 'init')
self.certificate()
self.add_tls()
@@ -471,6 +479,7 @@ basicConstraints = critical,CA:TRUE"""
(resp, sock) = self.get_ssl(
headers={'Host': 'localhost', 'Connection': 'keep-alive'},
start=True,
read_timeout=1,
)
self.conf({"application": "empty"}, 'listeners/*:7080')
@@ -501,6 +510,8 @@ basicConstraints = critical,CA:TRUE"""
self.skip_alerts.append(r'process \d+ exited on signal 9')
self.load('mirror')
self.assertEqual(self.get()['status'], 200, 'init')
self.certificate()
self.conf('1', 'applications/mirror/processes')
@@ -515,6 +526,7 @@ basicConstraints = critical,CA:TRUE"""
},
start=True,
body='0123456789',
read_timeout=1,
)
app_id = self.findall(r'(\d+)#\d+ "mirror" application started')[0]