Skip to content

Commit

Permalink
Chore: improve test execution time: lower refresh and metrics intervals
Browse files Browse the repository at this point in the history
This commit lowers refresh and metrics intervals in tests, thereby
cutting about two minutes or so of the test suite execution time.

I'm worried, though, that it might make some tests more flaky.
  • Loading branch information
thomasheartman committed Mar 7, 2024
1 parent 2f4a2ff commit 1abe74e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
24 changes: 12 additions & 12 deletions tests/unit_tests/test_client.py
Expand Up @@ -210,7 +210,7 @@ def test_uc_lifecycle(unleash_client):
status=304,
headers={"etag": ETAG_VALUE},
)
time.sleep(16)
time.sleep(REFRESH_INTERVAL + 1)

# Simulate server provisioning change
responses.add(
Expand All @@ -220,7 +220,7 @@ def test_uc_lifecycle(unleash_client):
status=200,
headers={"etag": "W/somethingelse"},
)
time.sleep(30)
time.sleep(REFRESH_INTERVAL * 2)
assert len(unleash_client.features) >= 9


Expand Down Expand Up @@ -329,13 +329,13 @@ def test_uc_dirty_cache(unleash_client_nodestroy):

# Create Unleash client and check initial load
unleash_client.initialize_client()
time.sleep(5)
time.sleep(1)
assert unleash_client.is_enabled("testFlag")
unleash_client.unleash_scheduler.shutdown()

# Check that everything works if previous cache exists.
unleash_client.initialize_client()
time.sleep(5)
time.sleep(1)
assert unleash_client.is_enabled("testFlag")


Expand Down Expand Up @@ -484,7 +484,7 @@ def test_uc_metrics(unleash_client):
time.sleep(1)
assert unleash_client.is_enabled("testFlag")

time.sleep(12)
time.sleep(METRICS_INTERVAL)
request = json.loads(responses.calls[-1].request.body)
assert request["bucket"]["toggles"]["testFlag"]["yes"] == 1

Expand All @@ -506,7 +506,7 @@ def test_uc_registers_metrics_for_nonexistent_features(unleash_client):
unleash_client.is_enabled("nonexistent-flag")

# Verify that the metrics are serialized
time.sleep(12)
time.sleep(METRICS_INTERVAL)
request = json.loads(responses.calls[-1].request.body)
assert request["bucket"]["toggles"]["nonexistent-flag"]["no"] == 1

Expand All @@ -526,7 +526,7 @@ def test_uc_metrics_dependencies(unleash_client):
time.sleep(1)
assert unleash_client.is_enabled("Child")

time.sleep(12)
time.sleep(METRICS_INTERVAL)
request = json.loads(responses.calls[-1].request.body)
assert request["bucket"]["toggles"]["Child"]["yes"] == 1
assert "Parent" not in request["bucket"]["toggles"]
Expand All @@ -549,7 +549,7 @@ def test_uc_registers_variant_metrics_for_nonexistent_features(unleash_client):
unleash_client.get_variant("nonexistent-flag")

# Verify that the metrics are serialized
time.sleep(12)
time.sleep(METRICS_INTERVAL)
request = json.loads(responses.calls[-1].request.body)
assert request["bucket"]["toggles"]["nonexistent-flag"]["no"] == 1
assert request["bucket"]["toggles"]["nonexistent-flag"]["variants"]["disabled"] == 1
Expand Down Expand Up @@ -578,7 +578,7 @@ def test_uc_doesnt_count_metrics_for_dependency_parents(unleash_client):
unleash_client.get_variant(child)

# Verify that the parent doesn't have any metrics registered
time.sleep(12)
time.sleep(METRICS_INTERVAL)
request = json.loads(responses.calls[-1].request.body)
assert request["bucket"]["toggles"][child]["yes"] == 2
assert request["bucket"]["toggles"][child]["variants"]["childVariant"] == 1
Expand Down Expand Up @@ -608,7 +608,7 @@ def test_uc_counts_metrics_for_child_even_if_parent_is_disabled(unleash_client):
unleash_client.get_variant(child)

# Verify that the parent doesn't have any metrics registered
time.sleep(12)
time.sleep(METRICS_INTERVAL)
request = json.loads(responses.calls[-1].request.body)
assert request["bucket"]["toggles"][child]["no"] == 2
assert request["bucket"]["toggles"][child]["variants"]["disabled"] == 1
Expand All @@ -627,7 +627,7 @@ def test_uc_disabled_registration(unleash_client_toggle_only):

unleash_client.initialize_client()
unleash_client.is_enabled("testFlag")
time.sleep(20)
time.sleep(REFRESH_INTERVAL * 2)
assert unleash_client.is_enabled("testFlag")

for api_call in responses.calls:
Expand All @@ -650,7 +650,7 @@ def test_uc_server_error(unleash_client):
responses.add(
responses.GET, URL + FEATURES_URL, json=MOCK_FEATURE_RESPONSE, status=200
)
time.sleep(20)
time.sleep(REFRESH_INTERVAL * 2)
assert unleash_client.is_enabled("testFlag")


Expand Down
4 changes: 2 additions & 2 deletions tests/utilities/testing_constants.py
Expand Up @@ -14,9 +14,9 @@
APP_NAME = "pytest"
ENVIRONMENT = "unit"
INSTANCE_ID = "123"
REFRESH_INTERVAL = 15
REFRESH_INTERVAL = 3
REFRESH_JITTER = None
METRICS_INTERVAL = 10
METRICS_INTERVAL = 2
METRICS_JITTER = None
DISABLE_METRICS = True
DISABLE_REGISTRATION = True
Expand Down

0 comments on commit 1abe74e

Please sign in to comment.