From 17e9c0018044db53f2c427adbc5e75c4ae864ccc Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Wed, 14 Sep 2022 15:09:00 +0200 Subject: [PATCH] UT: Add another test for AgentEventsToIslandSender --- .../test_send_all_events_to_island.py | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/monkey/tests/unit_tests/infection_monkey/test_send_all_events_to_island.py b/monkey/tests/unit_tests/infection_monkey/test_send_all_events_to_island.py index dc05d6b86..21c21b2a3 100644 --- a/monkey/tests/unit_tests/infection_monkey/test_send_all_events_to_island.py +++ b/monkey/tests/unit_tests/infection_monkey/test_send_all_events_to_island.py @@ -10,10 +10,9 @@ SERVER = "1.1.1.1:9999" @pytest.fixture def event_sender(): - return AgentEventsToIslandSender(SERVER) + return AgentEventsToIslandSender(SERVER, time_period=0.001) -# @pytest.mark.skipif(os.name != "posix", reason="This test is racey on Windows") def test_send_events(event_sender): with requests_mock.Mocker() as mock: mock.post(EVENTS_API_URL % SERVER) @@ -22,11 +21,27 @@ def test_send_events(event_sender): for _ in range(5): event_sender.add_event_to_queue({}) - time.sleep(1) - assert mock.call_count == 5 + time.sleep(0.1) + assert mock.call_count == 1 event_sender.add_event_to_queue({}) - time.sleep(1) - assert mock.call_count == 6 + time.sleep(0.1) + assert mock.call_count == 2 event_sender.stop() + + +def test_send_remaining_events(event_sender): + with requests_mock.Mocker() as mock: + mock.post(EVENTS_API_URL % SERVER) + + event_sender.start() + + for _ in range(5): + event_sender.add_event_to_queue({}) + time.sleep(0.1) + assert mock.call_count == 1 + + event_sender.add_event_to_queue({}) + event_sender.stop() + assert mock.call_count == 2