Skip to content

Commit 5fd01cf

Browse files
abrookinsclaude
andcommitted
Improve test worker isolation by overriding APPLIED_MIGRATIONS_KEY
Simplify the worker isolation approach by overriding the class constant APPLIED_MIGRATIONS_KEY instead of overriding individual methods. This ensures all methods that use the constant (including status()) use worker-specific keys. The previous approach missed that status() -> get_applied() -> uses APPLIED_MIGRATIONS_KEY causing cross-worker contamination in migration state tracking. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 929a22c commit 5fd01cf

File tree

1 file changed

+3
-17
lines changed

1 file changed

+3
-17
lines changed

tests/test_schema_migrator.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -111,26 +111,12 @@ class _WorkerAwareSchemaMigrator(SchemaMigrator):
111111
def __init__(self, redis_client, migrations_dir):
112112
super().__init__(redis_client, migrations_dir)
113113
self.worker_prefix = get_worker_prefix()
114-
115-
def get_applied_migrations_key(self):
116-
"""Override to use worker-specific key."""
117-
return f"redis_om:schema_applied_migrations:{self.worker_prefix}"
118-
119-
async def get_applied(self):
120-
"""Get applied migrations using worker-specific key."""
121-
key = self.get_applied_migrations_key()
122-
applied = await self.redis.smembers(key)
123-
return applied if applied else set()
124-
125-
async def mark_applied(self, migration_id: str):
126-
"""Mark migration as applied using worker-specific key."""
127-
key = self.get_applied_migrations_key()
128-
await self.redis.sadd(key, migration_id)
114+
# Override the class constant with worker-specific key
115+
self.APPLIED_MIGRATIONS_KEY = f"redis_om:schema_applied_migrations:{self.worker_prefix}"
129116

130117
async def mark_unapplied(self, migration_id: str):
131118
"""Mark migration as unapplied using worker-specific key."""
132-
key = self.get_applied_migrations_key()
133-
await self.redis.srem(key, migration_id)
119+
await self.redis.srem(self.APPLIED_MIGRATIONS_KEY, migration_id)
134120

135121

136122
# Test helper classes for rollback testing

0 commit comments

Comments
 (0)