Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chillaq committed Feb 28, 2023
1 parent a9ed304 commit 60c5541
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
26 changes: 12 additions & 14 deletions tests/sync/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import threading
import unittest.mock as mock
import time
import pytest

from splitio.api.auth import AuthAPI
from splitio.api import auth, client, APIException
Expand Down Expand Up @@ -73,26 +74,23 @@ def test_start_streaming_false(self, mocker):
assert len(synchronizer.start_periodic_data_recording.mock_calls) == 1

def test_telemetry(self, mocker):
httpclient = mocker.Mock(spec=client.HttpClient)
token = "eyJhbGciOiJIUzI1NiIsImtpZCI6IjVZOU05US45QnJtR0EiLCJ0eXAiOiJKV1QifQ.eyJ4LWFibHktY2FwYWJpbGl0eSI6IntcIk56TTJNREk1TXpjMF9NVGd5TlRnMU1UZ3dOZz09X3NlZ21lbnRzXCI6W1wic3Vic2NyaWJlXCJdLFwiTnpNMk1ESTVNemMwX01UZ3lOVGcxTVRnd05nPT1fc3BsaXRzXCI6W1wic3Vic2NyaWJlXCJdLFwiY29udHJvbF9wcmlcIjpbXCJzdWJzY3JpYmVcIixcImNoYW5uZWwtbWV0YWRhdGE6cHVibGlzaGVyc1wiXSxcImNvbnRyb2xfc2VjXCI6W1wic3Vic2NyaWJlXCIsXCJjaGFubmVsLW1ldGFkYXRhOnB1Ymxpc2hlcnNcIl19IiwieC1hYmx5LWNsaWVudElkIjoiY2xpZW50SWQiLCJleHAiOjE2MDIwODgxMjcsImlhdCI6MTYwMjA4NDUyN30.5_MjWonhs6yoFhw44hNJm3H7_YMjXpSW105DwjjppqE"
payload = '{{"pushEnabled": true, "token": "{token}"}}'.format(token=token)
cfg = DEFAULT_CONFIG.copy()
cfg.update({'IPAddressesEnabled': True, 'machineName': 'some_machine_name', 'machineIp': '123.123.123.123'})
sdk_metadata = get_metadata(cfg)
httpclient.get.return_value = client.HttpResponse(200, payload)
telemetry_storage = InMemoryTelemetryStorage()
telemetry_producer = TelemetryStorageProducer(telemetry_storage)
telemetry_runtime_producer = telemetry_producer.get_telemetry_runtime_producer()
auth_api = auth.AuthAPI(httpclient, 'some_api_key', sdk_metadata, telemetry_runtime_producer)
splits_ready_event = threading.Event()
synchronizer = mocker.Mock(spec=Synchronizer)
telemetry_storage = InMemoryTelemetryStorage()
telemetry_producer = TelemetryStorageProducer(telemetry_storage)
telemetry_runtime_producer = telemetry_producer.get_telemetry_runtime_producer()
manager = Manager(splits_ready_event, synchronizer, auth_api, True, sdk_metadata, telemetry_runtime_producer)
manager.start()
manager = Manager(splits_ready_event, synchronizer, mocker.Mock(), True, SdkMetadata('1.0', 'some', '1.2.3.4'), telemetry_runtime_producer)
try:
manager.start()
except:
pass
splits_ready_event.wait(2)

manager._queue.put(Status.PUSH_SUBSYSTEM_UP)
manager._queue.put(Status.PUSH_NONRETRYABLE_ERROR)
time.sleep(1)
manager._push_status_handler_active = True
assert(telemetry_storage._streaming_events._streaming_events[len(telemetry_storage._streaming_events._streaming_events)-2]._type == StreamingEventTypes.SYNC_MODE_UPDATE.value)
assert(telemetry_storage._streaming_events._streaming_events[len(telemetry_storage._streaming_events._streaming_events)-2]._data == SSESyncMode.STREAMING.value)
assert(telemetry_storage._streaming_events._streaming_events[len(telemetry_storage._streaming_events._streaming_events)-1]._type == StreamingEventTypes.SYNC_MODE_UPDATE.value)
assert(telemetry_storage._streaming_events._streaming_events[len(telemetry_storage._streaming_events._streaming_events)-1]._data == SSESyncMode.POLLING.value)

Expand Down
2 changes: 1 addition & 1 deletion tests/sync/test_splits_synchronizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ def test_split_condition_sanitization(self, mocker):
target_split = splits_json["splitChange1_1"]["splits"].copy()
target_split[0]["conditions"][0]['partitions'][0]['size'] = 0
target_split[0]["conditions"][0]['partitions'][1]['size'] = 100
split[0]["conditions"] = None
del split[0]["conditions"]
assert (split_synchronizer._sanitize_split_elements(split) == target_split)

# test missing ALL_KEYS condition matcher with default rule set to 100% off
Expand Down

0 comments on commit 60c5541

Please sign in to comment.