UT: Add another test for AgentEventsToIslandSender

This commit is contained in:
Ilija Lazoroski 2022-09-14 15:09:00 +02:00
parent 97a9f2d156
commit 17e9c00180
1 changed files with 21 additions and 6 deletions

View File

@ -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