Skip to content

Commit b1c56a6

Browse files
authored
test: address intermittent test failures (#394)
* address intermittent test failures and some warnings * format/lint * replace wait with polling * fix testcase
1 parent a25850f commit b1c56a6

3 files changed

Lines changed: 70 additions & 26 deletions

File tree

test/integration/models/test_database.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ def test_get_types(test_linode_client):
101101
client = test_linode_client
102102
types = client.database.types()
103103

104-
assert (types[0].type_class, "nanode")
105-
assert (types[0].id, "g6-nanode-1")
106-
assert (types[0].engines.mongodb[0].price.monthly, 15)
104+
assert "nanode" in types[0].type_class
105+
assert "g6-nanode-1" in types[0].id
106+
assert types[0].engines.mongodb[0].price.monthly == 15
107107

108108

109109
def test_get_engines(test_linode_client):

test/integration/models/test_linode.py

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
wait_for_condition,
77
)
88

9+
import polling
910
import pytest
1011

11-
from linode_api4 import VPCIPAddress
12+
from linode_api4 import LinodeClient, VPCIPAddress
1213
from linode_api4.errors import ApiError
1314
from linode_api4.objects import (
1415
Config,
@@ -84,7 +85,7 @@ def linode_for_network_interface_tests(test_linode_client):
8485
linode_instance.delete()
8586

8687

87-
@pytest.fixture(scope="session", autouse=True)
88+
@pytest.fixture
8889
def linode_for_disk_tests(test_linode_client):
8990
client = test_linode_client
9091
available_regions = client.regions()
@@ -94,21 +95,24 @@ def linode_for_disk_tests(test_linode_client):
9495
linode_instance, password = client.linode.instance_create(
9596
"g6-nanode-1",
9697
chosen_region,
97-
image="linode/debian10",
98+
image="linode/alpine3.19",
9899
label=label + "_long_tests",
99100
)
100101

101-
time.sleep(10)
102-
103102
# Provisioning time
104103
wait_for_condition(10, 300, get_status, linode_instance, "running")
105104

106-
time.sleep(10)
107-
108105
linode_instance.shutdown()
109106

110107
wait_for_condition(10, 100, get_status, linode_instance, "offline")
111108

109+
# Now it allocates 100% disk space hence need to clear some space for tests
110+
linode_instance.disks[1].delete()
111+
112+
test_linode_client.polling.event_poller_create(
113+
"linode", "disk_delete", entity_id=linode_instance.id
114+
)
115+
112116
yield linode_instance
113117

114118
linode_instance.delete()
@@ -138,6 +142,10 @@ def get_status(linode: Instance, status: str):
138142
return linode.status == status
139143

140144

145+
def instance_type_condition(linode: Instance, type: str):
146+
return type in str(linode.type)
147+
148+
141149
def test_get_linode(test_linode_client, linode_with_volume_firewall):
142150
linode = test_linode_client.load(Instance, linode_with_volume_firewall.id)
143151

@@ -303,6 +311,7 @@ def test_linode_resize_with_class(
303311

304312

305313
def test_linode_resize_with_migration_type(
314+
test_linode_client,
306315
create_linode_for_long_running_tests,
307316
):
308317
linode = create_linode_for_long_running_tests
@@ -311,18 +320,32 @@ def test_linode_resize_with_migration_type(
311320
wait_for_condition(10, 100, get_status, linode, "running")
312321

313322
time.sleep(5)
314-
res = linode.resize(new_type="g6-standard-1", migration_type=m_type)
315323

316-
assert res
324+
assert "g6-nanode-1" in str(linode.type)
325+
assert linode.specs.disk == 25600
317326

318-
wait_for_condition(10, 300, get_status, linode, "resizing")
327+
res = linode.resize(new_type="g6-standard-1", migration_type=m_type)
319328

320-
assert linode.status == "resizing"
329+
if res:
330+
# there is no resizing state in warm migration anymore hence wait for resizing and poll event
331+
test_linode_client.polling.event_poller_create(
332+
"linode", "linode_resize", entity_id=linode.id
333+
).wait_for_next_event_finished(interval=5)
334+
335+
wait_for_condition(
336+
10,
337+
100,
338+
get_status,
339+
linode,
340+
"running",
341+
)
342+
else:
343+
raise ApiError
321344

322-
# Takes about 3-5 minute to resize, sometimes longer...
323-
wait_for_condition(30, 600, get_status, linode, "running")
345+
# reload resized linode
346+
resized_linode = test_linode_client.load(Instance, linode.id)
324347

325-
assert linode.status == "running"
348+
assert resized_linode.specs.disk == 51200
326349

327350

328351
def test_linode_boot_with_config(create_linode):
@@ -376,10 +399,9 @@ def test_disk_resize_and_duplicate(test_linode_client, linode_for_disk_tests):
376399

377400
disk = linode.disks[0]
378401

379-
disk.resize(5000)
402+
send_request_when_resource_available(300, disk.resize, 5000)
380403

381-
# Using hard sleep instead of wait as the status shows ready when it is resizing
382-
time.sleep(120)
404+
time.sleep(100)
383405

384406
disk = test_linode_client.load(Disk, linode.disks[0].id, linode.id)
385407

@@ -397,7 +419,11 @@ def test_disk_resize_and_duplicate(test_linode_client, linode_for_disk_tests):
397419
def test_linode_create_disk(test_linode_client, linode_for_disk_tests):
398420
linode = test_linode_client.load(Instance, linode_for_disk_tests.id)
399421

400-
disk = linode.disk_create(size=500)
422+
disk = send_request_when_resource_available(
423+
300,
424+
linode.disk_create,
425+
size=500,
426+
)
401427

402428
wait_for_disk_status(disk, 120)
403429

test/integration/models/test_lke.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test_lke_node_delete(lke_cluster):
9595

9696
def test_lke_node_recycle(test_linode_client, lke_cluster):
9797
cluster = test_linode_client.load(LKECluster, lke_cluster.id)
98-
node = cluster.pools[0].nodes[0]
98+
9999
node_id = cluster.pools[0].nodes[0].id
100100

101101
send_request_when_resource_available(300, cluster.node_recycle, node_id)
@@ -106,9 +106,18 @@ def test_lke_node_recycle(test_linode_client, lke_cluster):
106106
assert node.status == "not_ready"
107107

108108
# wait for provisioning
109-
wait_for_condition(10, 300, get_node_status, cluster, "ready")
109+
wait_for_condition(
110+
10,
111+
500,
112+
get_node_status,
113+
test_linode_client.load(LKECluster, lke_cluster.id),
114+
"ready",
115+
)
110116

111-
node = cluster.pools[0].nodes[0]
117+
node_pool = test_linode_client.load(
118+
LKENodePool, cluster.pools[0].id, cluster.id
119+
)
120+
node = node_pool.nodes[0]
112121
assert node.status == "ready"
113122

114123

@@ -117,9 +126,18 @@ def test_lke_cluster_nodes_recycle(test_linode_client, lke_cluster):
117126

118127
send_request_when_resource_available(300, cluster.cluster_nodes_recycle)
119128

120-
wait_for_condition(5, 300, get_node_status, cluster, "not_ready")
129+
wait_for_condition(
130+
5,
131+
300,
132+
get_node_status,
133+
test_linode_client.load(LKECluster, cluster.id),
134+
"not_ready",
135+
)
121136

122-
node = cluster.pools[0].nodes[0]
137+
node_pool = test_linode_client.load(
138+
LKENodePool, cluster.pools[0].id, cluster.id
139+
)
140+
node = node_pool.nodes[0]
123141
assert node.status == "not_ready"
124142

125143

0 commit comments

Comments
 (0)