diff --git a/monkey/infection_monkey/monkey.py b/monkey/infection_monkey/monkey.py index 28e59c616..bd9062eeb 100644 --- a/monkey/infection_monkey/monkey.py +++ b/monkey/infection_monkey/monkey.py @@ -474,6 +474,7 @@ class InfectionMonkey(object): def run_ransomware(): telemetry_messenger = LegacyTelemetryMessengerAdapter() batching_telemetry_messenger = BatchingTelemetryMessenger(telemetry_messenger) + batching_telemetry_messenger.start() try: RansomewarePayload( WormConfiguration.ransomware, batching_telemetry_messenger diff --git a/monkey/infection_monkey/telemetry/messengers/batching_telemetry_messenger.py b/monkey/infection_monkey/telemetry/messengers/batching_telemetry_messenger.py index 6596e89e7..f5f21a760 100644 --- a/monkey/infection_monkey/telemetry/messengers/batching_telemetry_messenger.py +++ b/monkey/infection_monkey/telemetry/messengers/batching_telemetry_messenger.py @@ -28,14 +28,16 @@ class BatchingTelemetryMessenger(ITelemetryMessenger): self._last_sent_time = time.time() self._telemetry_batches: Dict[str, IBatchableTelem] = {} + def __del__(self): + self.stop() + + def start(self): + self._should_run_batch_thread = True self._manage_telemetry_batches_thread = threading.Thread( target=self._manage_telemetry_batches ) self._manage_telemetry_batches_thread.start() - def __del__(self): - self.stop() - def stop(self): self._should_run_batch_thread = False self._manage_telemetry_batches_thread.join() diff --git a/monkey/tests/unit_tests/infection_monkey/telemetry/messengers/test_batching_telemetry_messenger.py b/monkey/tests/unit_tests/infection_monkey/telemetry/messengers/test_batching_telemetry_messenger.py index 58ee96d89..65eebc582 100644 --- a/monkey/tests/unit_tests/infection_monkey/telemetry/messengers/test_batching_telemetry_messenger.py +++ b/monkey/tests/unit_tests/infection_monkey/telemetry/messengers/test_batching_telemetry_messenger.py @@ -57,6 +57,7 @@ class BatchableTelemStub(BatchableTelemMixin, BaseTelem, IBatchableTelem): def batching_telemetry_messenger(monkeypatch, telemetry_messenger_spy): patch_time(monkeypatch, 0) btm = BatchingTelemetryMessenger(telemetry_messenger_spy, period=0.001) + btm.start() yield btm btm.stop()