-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed memory leak in monitoring (#613)
* Fixed memory leak in monitoring Signed-off-by: Sergey Khoroshavin <[email protected]> * Removed unneeded check in test_warn_unordered_log_msg Signed-off-by: Sergey Khoroshavin <[email protected]> * Fixed flake8 errors Signed-off-by: Sergey Khoroshavin <[email protected]> * Minor fixes in monitor Signed-off-by: Sergey Khoroshavin <[email protected]>
- Loading branch information
1 parent
4b1f80e
commit 9a1ddbe
Showing
3 changed files
with
184 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import pytest | ||
|
||
from plenum.server.monitor import RequestTimeTracker | ||
import time | ||
|
||
INSTANCE_COUNT = 4 | ||
|
||
|
||
def test_request_tracker_start_adds_request(): | ||
req_tracker = RequestTimeTracker(INSTANCE_COUNT) | ||
req = ("id", 42) | ||
now = time.perf_counter() | ||
|
||
req_tracker.start(req[0], req[1], now) | ||
|
||
assert req in req_tracker | ||
assert req in [req for req, _ in req_tracker.unordered()] | ||
|
||
|
||
def test_request_tracker_order_by_master_makes_request_ordered_and_returns_time_to_order(): | ||
req_tracker = RequestTimeTracker(INSTANCE_COUNT) | ||
req = ("id", 42) | ||
now = time.perf_counter() | ||
req_tracker.start(req[0], req[1], now) | ||
|
||
tto = req_tracker.order(0, req[0], req[1], now + 5) | ||
|
||
assert req not in [req for req, _ in req_tracker.unordered()] | ||
assert tto == 5 | ||
|
||
|
||
def test_request_tracker_order_by_backup_returns_time_to_order(): | ||
req_tracker = RequestTimeTracker(INSTANCE_COUNT) | ||
req = ("id", 42) | ||
now = time.perf_counter() | ||
req_tracker.start(req[0], req[1], now) | ||
|
||
tto = req_tracker.order(1, req[0], req[1], now + 5) | ||
|
||
assert req in [req for req, _ in req_tracker.unordered()] | ||
assert tto == 5 | ||
|
||
|
||
def test_request_tracker_deletes_request_only_when_it_is_ordered_by_all_instances(): | ||
req_tracker = RequestTimeTracker(INSTANCE_COUNT) | ||
req = ("id", 42) | ||
now = time.perf_counter() | ||
req_tracker.start(req[0], req[1], now) | ||
|
||
for instId in range(INSTANCE_COUNT - 1): | ||
req_tracker.order(instId, req[0], req[1], now) | ||
assert req in req_tracker | ||
|
||
req_tracker.order(INSTANCE_COUNT - 1, req[0], req[1], now) | ||
assert req not in req_tracker | ||
|
||
|
||
def test_request_tracker_doesnt_wait_for_new_instances_on_old_requests(): | ||
req_tracker = RequestTimeTracker(INSTANCE_COUNT) | ||
req = ("id", 42) | ||
now = time.perf_counter() | ||
|
||
req_tracker.start(req[0], req[1], now) | ||
req_tracker.add_instance() | ||
|
||
for instId in range(INSTANCE_COUNT): | ||
req_tracker.order(instId, req[0], req[1], now) | ||
|
||
assert req not in req_tracker | ||
|
||
|
||
def test_request_tracker_waits_for_new_instances_on_new_requests(): | ||
req_tracker = RequestTimeTracker(INSTANCE_COUNT) | ||
req = ("id", 42) | ||
now = time.perf_counter() | ||
|
||
req_tracker.add_instance() | ||
req_tracker.start(req[0], req[1], now) | ||
|
||
for instId in range(INSTANCE_COUNT): | ||
req_tracker.order(instId, req[0], req[1], now) | ||
assert req in req_tracker | ||
|
||
req_tracker.order(INSTANCE_COUNT, req[0], req[1], now) | ||
assert req not in req_tracker | ||
|
||
|
||
def test_request_tracker_performs_garbage_collection_on_remove_instance(): | ||
req_tracker = RequestTimeTracker(INSTANCE_COUNT) | ||
req = ("id", 42) | ||
now = time.perf_counter() | ||
req_tracker.start(req[0], req[1], now) | ||
|
||
req_tracker.order(1, req[0], req[1], now) | ||
req_tracker.order(2, req[0], req[1], now) | ||
|
||
req_tracker.remove_instance(0) | ||
assert req in req_tracker | ||
|
||
req_tracker.remove_instance(2) | ||
assert req not in req_tracker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters