summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorAndrei Zeliankou <zelenkov@nginx.com>2022-09-27 12:08:36 +0100
committerAndrei Zeliankou <zelenkov@nginx.com>2022-09-27 12:08:36 +0100
commit97fa587c9f80ecee7bd2e2be173e700d011b09b9 (patch)
treea1255003691ef978441452a7f9ad6ca3d52ff77b /test
parent0711101af826cf7f5cb25050587ac6788ac0451c (diff)
downloadunit-97fa587c9f80ecee7bd2e2be173e700d011b09b9.tar.gz
unit-97fa587c9f80ecee7bd2e2be173e700d011b09b9.tar.bz2
Tests: added test with proxy for status.
Diffstat (limited to 'test')
-rw-r--r--test/test_status.py95
1 files changed, 51 insertions, 44 deletions
diff --git a/test/test_status.py b/test/test_status.py
index 214072d4..4c5e56ab 100644
--- a/test/test_status.py
+++ b/test/test_status.py
@@ -9,6 +9,23 @@ from unit.status import Status
class TestStatus(TestApplicationPython):
prerequisites = {'modules': {'python': 'any'}}
+ def check_connections(self, accepted, active, idle, closed):
+ Status.get('/connections') == {
+ 'accepted': accepted,
+ 'active': active,
+ 'idle': idle,
+ 'closed': closed,
+ }
+
+ def app_default(self, name="empty", module="wsgi"):
+ return {
+ "type": self.get_application_type(),
+ "processes": {"spare": 0},
+ "path": option.test_dir + "/python/" + name,
+ "working_directory": option.test_dir + "/python/" + name,
+ "module": module,
+ }
+
def test_status(self):
assert 'error' in self.conf_delete('/status'), 'DELETE method'
@@ -24,13 +41,7 @@ class TestStatus(TestApplicationPython):
},
"routes": [{"action": {"return": 200}}],
"applications": {
- "empty": {
- "type": self.get_application_type(),
- "processes": {"spare": 0},
- "path": option.test_dir + '/python/empty',
- "working_directory": option.test_dir + '/python/empty',
- "module": "wsgi",
- },
+ "empty": self.app_default(),
"blah": {
"type": self.get_application_type(),
"processes": {"spare": 0},
@@ -79,14 +90,6 @@ Connection: close
sock.close()
def test_status_connections(self):
- def check_connections(accepted, active, idle, closed):
- Status.get('/connections') == {
- 'accepted': accepted,
- 'active': active,
- 'idle': idle,
- 'closed': closed,
- }
-
assert 'success' in self.conf(
{
"listeners": {
@@ -95,14 +98,7 @@ Connection: close
},
"routes": [{"action": {"return": 200}}],
"applications": {
- "delayed": {
- "type": self.get_application_type(),
- "processes": {"spare": 0},
- "path": option.test_dir + "/python/delayed",
- "working_directory": option.test_dir
- + "/python/delayed",
- "module": "wsgi",
- },
+ "delayed": self.app_default("delayed"),
},
},
)
@@ -112,15 +108,15 @@ Connection: close
# accepted, closed
assert self.get()['status'] == 200
- check_connections(1, 0, 0, 1)
+ self.check_connections(1, 0, 0, 1)
# idle
_, sock = self.http(b'', start=True, raw=True, no_recv=True)
- check_connections(2, 0, 1, 1)
+ self.check_connections(2, 0, 1, 1)
self.get(sock=sock)
- check_connections(2, 0, 0, 2)
+ self.check_connections(2, 0, 0, 2)
# active
@@ -134,10 +130,10 @@ Connection: close
start=True,
read_timeout=1,
)
- check_connections(3, 1, 0, 2)
+ self.check_connections(3, 1, 0, 2)
self.get(sock=sock)
- check_connections(3, 0, 0, 3)
+ self.check_connections(3, 0, 0, 3)
def test_status_applications(self):
def check_applications(expert):
@@ -192,22 +188,8 @@ Connection: close
},
"routes": [],
"applications": {
- "restart": {
- "type": self.get_application_type(),
- "processes": {"spare": 0},
- "path": option.test_dir + "/python/restart",
- "working_directory": option.test_dir
- + "/python/restart",
- "module": "longstart",
- },
- "delayed": {
- "type": self.get_application_type(),
- "processes": {"spare": 0},
- "path": option.test_dir + "/python/delayed",
- "working_directory": option.test_dir
- + "/python/delayed",
- "module": "wsgi",
- },
+ "restart": self.app_default("restart", "longstart"),
+ "delayed": self.app_default("delayed"),
},
},
)
@@ -221,3 +203,28 @@ Connection: close
check_application('restart', 0, 1, 0, 1)
check_application('delayed', 0, 0, 0, 0)
+
+ def test_status_proxy(self):
+ assert 'success' in self.conf(
+ {
+ "listeners": {
+ "*:7080": {"pass": "routes"},
+ "*:7081": {"pass": "applications/empty"},
+ },
+ "routes": [
+ {
+ "match": {"uri": "/"},
+ "action": {"proxy": "http://127.0.0.1:7081"},
+ }
+ ],
+ "applications": {
+ "empty": self.app_default(),
+ },
+ },
+ )
+
+ Status.init()
+
+ assert self.get()['status'] == 200
+ self.check_connections(2, 0, 0, 2)
+ assert Status.get('/requests/total') == 2, 'proxy'