Skip to content

Commit 2de6405

Browse files
test(simint): clean up stale test models to prevent hitting limit (#2704)
1 parent e2152c0 commit 2de6405

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

  • tests/tests_integration/test_api/test_simulators

tests/tests_integration/test_api/test_simulators/conftest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
SimulatorRoutineRevisionWrite,
2121
SimulatorRoutineWrite,
2222
)
23+
from cognite.client.exceptions import CogniteAPIError
2324
from cognite.client.utils._async_helpers import run_sync
2425
from cognite.client.utils._text import to_snake_case
2526
from tests.tests_integration.test_api.test_simulators.seed.data import (
@@ -160,6 +161,22 @@ def seed_simulator_models(
160161
models = cognite_client.simulators.models.list(limit=None)
161162
model = models.get(external_id=model_unique_external_id)
162163

164+
two_hours_ago_ms = int(time.time() * 1000) - 2 * 60 * 60 * 1000
165+
stale_ids = [
166+
m.external_id
167+
for m in models
168+
if m.external_id
169+
and m.external_id.startswith("py_sdk_integration_tests_model_")
170+
and m.external_id != model_unique_external_id
171+
and m.created_time is not None
172+
and m.created_time < two_hours_ago_ms
173+
]
174+
if stale_ids:
175+
try:
176+
cognite_client.simulators.models.delete(external_ids=stale_ids)
177+
except CogniteAPIError:
178+
pass
179+
163180
if not model:
164181
new_model = SimulatorModelWrite._load(
165182
{

0 commit comments

Comments
 (0)