Tests: Ensure cleanup of batching_telemetry_messenger

Since an "assert" halts a test, the BatchingTelemetryMessenger may not
be deconstructed. This results in pytest hanging. By adding a finally
clause, we ensure the cleanup of the BatchingTelemetryMessenger.
This commit is contained in:
Mike Salvatore 2021-07-20 12:23:13 -04:00
parent 42dcb697e9
commit 4affb11128
1 changed files with 52 additions and 38 deletions

View File

@ -69,8 +69,11 @@ def test_send_immediately(monkeypatch, telemetry_messenger_spy):
batching_telemetry_messenger.send_telemetry(telem)
release_GIL()
try:
assert len(telemetry_messenger_spy.telemetries) == 1
assert telemetry_messenger_spy.telemetries[0] == telem
finally:
del batching_telemetry_messenger
def test_send_telem_batch(monkeypatch, telemetry_messenger_spy):
@ -78,6 +81,7 @@ def test_send_telem_batch(monkeypatch, telemetry_messenger_spy):
monkeypatch, telemetry_messenger_spy
)
try:
expected_data = {"entries": [1, 2]}
telem1 = BatchableTelemStub(1)
telem2 = BatchableTelemStub(2)
@ -92,6 +96,8 @@ def test_send_telem_batch(monkeypatch, telemetry_messenger_spy):
assert len(telemetry_messenger_spy.telemetries) == 1
assert telemetry_messenger_spy.telemetries[0].get_data() == expected_data
finally:
del batching_telemetry_messenger
def test_send_different_telem_types(monkeypatch, telemetry_messenger_spy):
@ -99,6 +105,7 @@ def test_send_different_telem_types(monkeypatch, telemetry_messenger_spy):
monkeypatch, telemetry_messenger_spy
)
try:
telem1 = BatchableTelemStub(1, "cat1")
telem2 = BatchableTelemStub(2, "cat2")
@ -113,6 +120,8 @@ def test_send_different_telem_types(monkeypatch, telemetry_messenger_spy):
assert len(telemetry_messenger_spy.telemetries) == 2
assert telemetry_messenger_spy.telemetries[0] == telem1
assert telemetry_messenger_spy.telemetries[1] == telem2
finally:
del batching_telemetry_messenger
def test_send_two_batches(monkeypatch, telemetry_messenger_spy):
@ -120,6 +129,7 @@ def test_send_two_batches(monkeypatch, telemetry_messenger_spy):
monkeypatch, telemetry_messenger_spy
)
try:
telem1 = BatchableTelemStub(1, "cat1")
telem2 = BatchableTelemStub(2, "cat1")
@ -136,6 +146,8 @@ def test_send_two_batches(monkeypatch, telemetry_messenger_spy):
assert len(telemetry_messenger_spy.telemetries) == 2
assert telemetry_messenger_spy.telemetries[1] == telem2
finally:
del batching_telemetry_messenger
def test_send_remaining_telem_after_stop(monkeypatch, telemetry_messenger_spy):
@ -149,7 +161,9 @@ def test_send_remaining_telem_after_stop(monkeypatch, telemetry_messenger_spy):
batching_telemetry_messenger.send_telemetry(telem)
release_GIL()
try:
assert len(telemetry_messenger_spy.telemetries) == 0
finally:
del batching_telemetry_messenger
assert len(telemetry_messenger_spy.telemetries) == 1