Skip to content

Commit f442831

Browse files
authored
chore: correct resource pool comparison in tests (#433)
This was causing tests to fail sporadically. Closes #432.
1 parent 72b9440 commit f442831

2 files changed

Lines changed: 18 additions & 14 deletions

File tree

components/renku_data_services/crc/models.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -212,18 +212,17 @@ def __eq__(self, other: Any) -> bool:
212212
if not isinstance(other, ResourcePool):
213213
return False
214214

215-
if self.id != other.id:
216-
return False
217-
if self.name != other.name:
218-
return False
219-
if self.default != other.default or self.public != other.public:
220-
return False
221-
if self.idle_threshold != other.idle_threshold or self.hibernation_threshold != other.hibernation_threshold:
222-
return False
223-
224-
this_classes = sorted(self.classes, key=lambda x: (x.default, x.cpu, x.memory, x.default_storage, x.name))
225-
other_classes = sorted(other.classes, key=lambda x: (x.default, x.cpu, x.memory, x.default_storage, x.name))
226-
return this_classes == other_classes
215+
return (
216+
self.id == other.id
217+
and self.name == other.name
218+
and self.default == other.default
219+
and self.public == other.public
220+
and self.idle_threshold == other.idle_threshold
221+
and self.hibernation_threshold == other.hibernation_threshold
222+
and self.quota == other.quota
223+
and sorted(self.classes, key=lambda x: x.id or x.name)
224+
== sorted(other.classes, key=lambda x: x.id or x.name)
225+
)
227226

228227
def set_quota(self, val: Quota) -> "ResourcePool":
229228
"""Set the quota for a resource pool."""

test/components/renku_data_services/db/test_sqlalchemy_pool_repo.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,16 @@ async def test_resource_pool_update_classes(
119119

120120
assert updated_rp.id == inserted_rp.id
121121
assert len(updated_rp.classes) == len(inserted_rp.classes)
122-
assert updated_rp.classes == new_classes_models
122+
assert sorted(
123+
updated_rp.classes,
124+
key=lambda x: x.id or x.name,
125+
) == sorted(
126+
new_classes_models,
127+
key=lambda x: x.id or x.name,
128+
)
123129
retrieved_rps = await pool_repo.get_resource_pools(id=inserted_rp.id, api_user=admin_user)
124130
assert len(retrieved_rps) == 1
125131
assert retrieved_rps[0] == updated_rp
126-
assert retrieved_rps[0].classes == updated_rp.classes
127132
except (ValidationError, errors.ValidationError):
128133
pass
129134
finally:

0 commit comments

Comments
 (0)