Skip to content

Commit 23089eb

Browse files
committed
Fix flaky integration tests
1 parent 416f7a9 commit 23089eb

4 files changed

Lines changed: 27 additions & 23 deletions

File tree

test/integration/linode_client/test_linode_client.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22
import time
33
from test.integration.conftest import get_region
4-
from test.integration.helpers import get_test_label
4+
from test.integration.helpers import get_test_label, wait_for_condition
55

66
import pytest
77

@@ -55,10 +55,11 @@ def test_fails_to_create_domain_without_soa_email(setup_client_and_linode):
5555

5656
timestamp = str(time.time_ns())
5757
domain_addr = timestamp + "example.com"
58-
try:
59-
domain = client.domain_create(domain=domain_addr)
60-
except ApiError as e:
61-
assert e.status == 400
58+
59+
with pytest.raises(ApiError) as exc_info:
60+
client.domain_create(domain=domain_addr)
61+
62+
assert exc_info.value.status == 400
6263

6364

6465
@pytest.mark.smoke
@@ -90,11 +91,16 @@ def test_get_regions(test_linode_client):
9091
def test_image_create(setup_client_and_linode):
9192
client = setup_client_and_linode[0]
9293
linode = setup_client_and_linode[1]
93-
9494
label = get_test_label()
9595
description = "Test description"
9696
tags = ["test"]
97-
usable_disk = [v for v in linode.disks if v.filesystem != "swap"]
97+
98+
def linode_disks_are_ready(linode_instance):
99+
linode_instance.invalidate()
100+
disks = [d for d in linode_instance.disks if d.filesystem != "swap"]
101+
return disks if disks else None
102+
103+
usable_disk = wait_for_condition(5, 120, linode_disks_are_ready, linode)
98104

99105
image = client.image_create(
100106
disk=usable_disk[0].id, label=label, description=description, tags=tags
@@ -116,23 +122,23 @@ def test_fails_to_create_image_with_non_existing_disk_id(
116122
description = "Test description"
117123
disk_id = 111111
118124

119-
try:
125+
with pytest.raises(ApiError) as exc_info:
120126
client.image_create(disk=disk_id, label=label, description=description)
121-
except ApiError as e:
122-
assert 400 <= e.status < 500
127+
128+
# TODO: Specific status code may be used when defect is solved: ARB-7797
129+
assert 400 <= exc_info.value.status < 500
123130

124131

125132
def test_fails_to_delete_predefined_images(setup_client_and_linode):
126133
client = setup_client_and_linode[0]
127134

128135
images = client.images()
129136

130-
try:
137+
with pytest.raises(ApiError, match="Unauthorized") as exc_info:
131138
# new images go on top of the list thus choose last image
132139
images.last().delete()
133-
except ApiError as e:
134-
assert "Unauthorized" in str(e.json)
135-
assert e.status == 403
140+
141+
assert exc_info.value.status == 403
136142

137143

138144
def test_get_volume(test_linode_client, test_volume):
@@ -345,16 +351,15 @@ def test_fails_to_create_cluster_with_invalid_version(test_linode_client):
345351
client = test_linode_client
346352
region = get_region(client, {"Kubernetes"}).id
347353

348-
try:
349-
cluster = client.lke.cluster_create(
354+
with pytest.raises(ApiError, match="not valid") as exc_info:
355+
client.lke.cluster_create(
350356
region,
351357
"example-cluster",
352358
invalid_version,
353359
{"type": "g6-standard-1", "count": 3},
354360
)
355-
except ApiError as e:
356-
assert "not valid" in str(e.json)
357-
assert e.status == 400
361+
362+
assert exc_info.value.status == 400
358363

359364

360365
# ObjectStorageGroupTests

test/integration/models/domain/test_domain.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ def test_clone(test_linode_client, test_domain):
4343
dom = "example.clone-" + timestamp + "-inttestsdk.org"
4444
domain.clone(dom)
4545

46-
time.sleep(1)
46+
time.sleep(3)
4747

4848
ds = test_linode_client.domains()
49-
5049
domains = [i.domain for i in ds]
5150

5251
assert dom in domains

test/integration/models/linode/test_linode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def test_linode_rebuild(test_linode_client):
304304
root_pass="aComplex@Password123",
305305
)
306306

307-
wait_for_condition(10, 100, get_status, linode, "running")
307+
wait_for_condition(10, 150, get_status, linode, "running")
308308

309309
retry_sending_request(
310310
3,

test/integration/models/placement/test_placement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def test_pg_migration(
9292

9393
# Says it could take up to ~6 hrs for migration to fully complete
9494
send_request_when_resource_available(
95-
300,
95+
400,
9696
linode.initiate_migration,
9797
placement_group=pg_inbound.id,
9898
migration_type=MigrationType.COLD,

0 commit comments

Comments
 (0)