implement gitlab blue-green ci cd
This commit is contained in:
1 parent
a353b80a15
commit
0f2dee08cb
13 files changed
+686
-230
No files matched your search
@@ -0,0 +1,46 @@
|
||||
import asyncio
|
||||
import os
|
||||
from contextlib import suppress
|
||||
from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
from redis.asyncio import Redis
|
||||
from redis.exceptions import RedisError
|
||||
|
||||
from warehouse_allocation.infrastructure.inventory import RedisInventoryRepository
|
||||
|
||||
|
||||
@pytest.mark.redis
|
||||
async def test_real_redis_reservation_is_atomic() -> None:
|
||||
redis_url = os.getenv("WA_TEST_REDIS_URL")
|
||||
if not redis_url:
|
||||
pytest.skip("WA_TEST_REDIS_URL is not configured")
|
||||
|
||||
client = Redis.from_url(redis_url, decode_responses=True)
|
||||
repository = RedisInventoryRepository(client)
|
||||
warehouse_id = f"ci-{uuid4().hex}"
|
||||
key = f"inventory:{warehouse_id}"
|
||||
|
||||
try:
|
||||
for _attempt in range(20):
|
||||
try:
|
||||
if await client.ping():
|
||||
break
|
||||
except RedisError:
|
||||
await asyncio.sleep(0.25)
|
||||
else:
|
||||
pytest.fail("Redis integration service did not become ready")
|
||||
|
||||
await repository.set_levels(warehouse_id, {"ATOMIC-SKU": 5})
|
||||
|
||||
results = await asyncio.gather(
|
||||
repository.reserve(warehouse_id, {"ATOMIC-SKU": 4}),
|
||||
repository.reserve(warehouse_id, {"ATOMIC-SKU": 4}),
|
||||
)
|
||||
|
||||
assert sorted(results) == [False, True]
|
||||
assert await client.hget(key, "ATOMIC-SKU") == "1"
|
||||
finally:
|
||||
with suppress(RedisError):
|
||||
await client.delete(key)
|
||||
await repository.close()
|
||||
Reference in new issue
Block a user