Skip to content

Commit 45954e9

Browse files
committed
fix: only clean up channel types older than 2 minutes
Prevents parallel runners from deleting each other's freshly created channel types while still freeing stale slots from previous runs.
1 parent f562179 commit 45954e9

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

tests/test_chat_misc.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import datetime
12
import time
23
import uuid
34

@@ -394,12 +395,21 @@ def test_query_future_channel_bans(client: Stream, random_users):
394395
"messaging", "livestream", "team", "gaming", "commerce",
395396
})
396397

398+
_STALE_THRESHOLD = datetime.timedelta(minutes=2)
399+
397400

398401
def _cleanup_test_channel_types(client: Stream):
399-
"""Delete non-builtin channel types to free slots for test runs."""
402+
"""Delete stale non-builtin channel types to free slots for test runs.
403+
404+
Only deletes types older than 2 minutes to avoid interfering with
405+
parallel runners that just created theirs.
406+
"""
407+
now = datetime.datetime.now(datetime.timezone.utc)
400408
resp = client.chat.list_channel_types()
401-
for name in resp.data.channel_types:
402-
if name not in BUILTIN_CHANNEL_TYPES:
409+
for name, config in resp.data.channel_types.items():
410+
if name in BUILTIN_CHANNEL_TYPES:
411+
continue
412+
if config and (now - config.created_at) > _STALE_THRESHOLD:
403413
try:
404414
client.chat.delete_channel_type(name=name)
405415
except Exception:

0 commit comments

Comments
 (0)