From aeda96db0615aadbffe980687bf146f36af031c1 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Wed, 14 Sep 2022 15:45:40 +0530 Subject: [PATCH] UT: Add test for AgentEventsToIslandSender --- .../test_send_all_events_to_island.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 monkey/tests/unit_tests/infection_monkey/test_send_all_events_to_island.py 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 new file mode 100644 index 000000000..0569015c4 --- /dev/null +++ b/monkey/tests/unit_tests/infection_monkey/test_send_all_events_to_island.py @@ -0,0 +1,33 @@ +import time + +import pytest +import requests_mock + +from infection_monkey.send_all_events_to_island import AgentEventsToIslandSender +from monkey.infection_monkey.send_all_events_to_island import EVENTS_API_URL + +SERVER = "1.1.1.1:9999" + + +@pytest.fixture +def event_sender(): + return AgentEventsToIslandSender(SERVER) + + +# @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) + + event_sender.start() + + for _ in range(5): + event_sender.add_event_to_queue({}) + time.sleep(1) + assert mock.call_count == 5 + + event_sender.add_event_to_queue({}) + time.sleep(1) + assert mock.call_count == 6 + + event_sender.stop()