diff options
author | Andrei Zeliankou <zelenkov@nginx.com> | 2022-09-05 23:06:16 +0100 |
---|---|---|
committer | Andrei Zeliankou <zelenkov@nginx.com> | 2022-09-05 23:06:16 +0100 |
commit | 6915ce1d1ca08ee72de1bafba1514a458b72116c (patch) | |
tree | 2e45cf7e1ca04fd7216d9c31cbc9cd91f6af1c3f /test/unit/status.py | |
parent | 3ea113fcb7261a0be3b9dc8d32c402da1bcfadaa (diff) | |
download | unit-6915ce1d1ca08ee72de1bafba1514a458b72116c.tar.gz unit-6915ce1d1ca08ee72de1bafba1514a458b72116c.tar.bz2 |
Tests: added tests for basic statistics.
Diffstat (limited to '')
-rw-r--r-- | test/unit/status.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/test/unit/status.py b/test/unit/status.py new file mode 100644 index 00000000..17416f17 --- /dev/null +++ b/test/unit/status.py @@ -0,0 +1,45 @@ +from unit.control import TestControl + + +class Status: + _status = None + control = TestControl() + + def _check_zeros(): + assert Status.control.conf_get('/status') == { + 'connections': { + 'accepted': 0, + 'active': 0, + 'idle': 0, + 'closed': 0, + }, + 'requests': {'total': 0}, + 'applications': {}, + } + + def init(status=None): + Status._status = ( + status if status is not None else Status.control.conf_get('/status') + ) + + def diff(): + def find_diffs(d1, d2): + if isinstance(d1, dict) and isinstance(d2, dict): + return { + k: find_diffs(d1.get(k, 0), d2.get(k, 0)) + for k in d1 + if k in d2 + } + else: + return d1 - d2 + + return find_diffs(Status.control.conf_get('/status'), Status._status) + + def get(path='/'): + path = path.split('/')[1:] + diff = Status.diff() + + for p in path: + diff = diff[p] + + return diff |