Skip to content

Commit c94a26e

Browse files
committed
spport eventsourcingdb version 0.118.*
1 parent edbb507 commit c94a26e

File tree

12 files changed

+109
-76
lines changed

12 files changed

+109
-76
lines changed

eventsourcingdb/event/event_candidate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class EventCandidate:
1010
subject: str
1111
type: str
1212
data: dict
13-
trace_parent: str = None
14-
trace_state: str = None
13+
trace_parent: str | None = None
14+
trace_state: str | None = None
1515

1616
"""def validate(self) -> None:
1717
validate_subject(self.subject)

eventsourcingdb/event/source.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def new_event(
1717
subject: str,
1818
event_type: str,
1919
data: dict,
20-
trace_parent: str = None,
21-
trace_state: str = None
20+
trace_parent: str | None = None,
21+
trace_state: str | None = None
2222
) -> EventCandidate:
2323
return EventCandidate(
2424
self.source,

tests/conftest.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from eventsourcingdb.event.event_candidate import EventCandidate
99
from eventsourcingdb.event.source import Source
1010
from eventsourcingdb.http_client.http_client import HttpClient
11-
from .shared.build_database import build_database
1211
from .shared.database import Database
1312

1413
from .shared.start_local_http_server import \
@@ -17,14 +16,6 @@
1716

1817
pytest_plugins = ('pytest_asyncio', )
1918

20-
if not hasattr(_pytest.fixtures.FixtureDef, "unittest"):
21-
_pytest.fixtures.FixtureDef.unittest = False
22-
23-
24-
def pytest_sessionstart():
25-
build_database('tests/shared/docker/eventsourcingdb')
26-
27-
2819
@pytest_asyncio.fixture
2920
async def get_http_client():
3021
stop_server: StopServer | None = None
@@ -77,7 +68,7 @@ class TestData:
7768
TEST_SOURCE_STRING = 'tag:thenativeweb.io,2023:eventsourcingdb:test'
7869
TEST_SOURCE = Source(TEST_SOURCE_STRING)
7970
REGISTERED_SUBJECT = '/users/registered'
80-
LOGGED_IN_SUBJECT = '/users/loggedIn'
71+
LOGGED_IN_SUBJECT = '/users/logged-in'
8172
REGISTERED_TYPE = 'io.thenativeweb.users.registered'
8273
LOGGED_IN_TYPE = 'io.thenativeweb.users.loggedIn'
8374
JANE_DATA = {'name': 'jane'}

tests/shared/build_database.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/shared/database.py

Lines changed: 64 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import uuid
2+
import time
23
from eventsourcingdb.client import Client
34
from eventsourcingdb.container import Container
45
from .testing_database import TestingDatabase
6+
import os
57

68
class Database:
79
__create_key = object()
@@ -19,34 +21,75 @@ def __init__(
1921
self.with_invalid_url: TestingDatabase = with_invalid_url
2022

2123
@classmethod
22-
async def create(cls) -> 'Database':
24+
async def create(cls, max_retries=3, retry_delay=2.0) -> 'Database':
25+
"""Create a new Database instance with retry mechanism for container startup"""
2326
api_token = str(uuid.uuid4())
2427

25-
# Erstellen und Starten des Containers mit der zentralen Container-Klasse
28+
dockerfile_path = os.path.join(os.path.dirname(__file__), 'docker/eventsourcingdb/Dockerfile')
29+
with open(dockerfile_path, 'r') as dockerfile:
30+
content = dockerfile.read().strip()
31+
image_tag = content.split(':')[-1]
32+
2633
container = Container(
27-
api_token=api_token
34+
image_name="thenativeweb/eventsourcingdb",
35+
image_tag=image_tag,
36+
api_token=api_token,
37+
internal_port=3000
2838
)
29-
container.start()
3039

31-
# Client mit Autorisierung erstellen
32-
with_authorization_client = container.get_client()
33-
await with_authorization_client.initialize()
34-
with_authorization = TestingDatabase(
35-
with_authorization_client,
36-
container # Container an TestingDatabase übergeben für cleanup
37-
)
40+
# Try with retries
41+
for attempt in range(max_retries):
42+
try:
43+
# Start the container with timeout handling
44+
container.start()
45+
46+
# Create client with authorization
47+
with_authorization_client = container.get_client()
48+
await with_authorization_client.initialize()
49+
with_authorization = TestingDatabase(
50+
with_authorization_client,
51+
container # Pass container to TestingDatabase for cleanup
52+
)
3853

39-
# Client mit ungültiger URL erstellen - api_token statt auth_token verwenden
40-
with_invalid_url_client = Client(
41-
base_url='http://localhost.invalid',
42-
api_token=api_token
43-
)
44-
await with_invalid_url_client.initialize()
45-
with_invalid_url = TestingDatabase(
46-
with_invalid_url_client
47-
)
54+
# Create client with invalid URL but valid token
55+
with_invalid_url_client = Client(
56+
base_url='http://localhost.invalid',
57+
api_token=api_token
58+
)
59+
await with_invalid_url_client.initialize()
60+
with_invalid_url = TestingDatabase(
61+
with_invalid_url_client
62+
)
4863

49-
return cls(Database.__create_key, with_authorization, with_invalid_url)
64+
return cls(Database.__create_key, with_authorization, with_invalid_url)
65+
66+
except Exception as e:
67+
# On the last attempt, raise the error
68+
if attempt == max_retries - 1:
69+
# Cleanup the container if it was created
70+
try:
71+
container.stop()
72+
except:
73+
pass
74+
raise RuntimeError(f"Failed to initialize database container after {max_retries} attempts: {e}")
75+
76+
# Otherwise wait and retry
77+
print(f"Container startup attempt {attempt+1} failed: {e}. Retrying in {retry_delay} seconds...")
78+
time.sleep(retry_delay)
79+
80+
# Try to clean up the failed container before retrying
81+
try:
82+
container.stop()
83+
except:
84+
pass
85+
86+
# Create a new container for the next attempt
87+
container = Container(
88+
image_name="thenativeweb/eventsourcingdb",
89+
image_tag="latest",
90+
api_token=api_token,
91+
internal_port=3000
92+
)
5093

5194
async def stop(self):
5295
await self.with_authorization.stop()

tests/shared/docker/__init__.py

Whitespace-only changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
FROM thenativeweb/eventsourcingdb:0.113.2
1+
FROM thenativeweb/eventsourcingdb:0.118.10

tests/shared/start_local_http_server.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ async def ping_app():
5454
try:
5555
await session.get(
5656
f"http://localhost:{local_http_server.port}/__python_test__/api/v1/ping",
57-
timeout=2
5857
)
5958
# Wenn die Anfrage erfolgreich ist, brechen wir die Schleife ab
6059
return True

tests/test_read_event_types.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,11 @@
99
from eventsourcingdb.errors.server_error import ServerError
1010
from eventsourcingdb.handlers.read_event_types.event_type import EventType
1111
from .conftest import TestData
12-
from .shared.build_database import build_database
1312
from .shared.database import Database
1413
from .shared.start_local_http_server import AttachHandlers, AttachHandler
1514

1615

1716
class TestReadEventTypes:
18-
@classmethod
19-
def setup_class(cls):
20-
build_database('tests/shared/docker/eventsourcingdb')
21-
2217
@staticmethod
2318
@pytest.mark.asyncio
2419
async def test_reads_all_types_of_existing_events_and_registered_schemas(
@@ -52,11 +47,11 @@ async def test_reads_all_types_of_existing_events_and_registered_schemas(
5247

5348
await client.register_event_schema(
5449
"org.ban.ban",
55-
{"type": "object"} # type: ignore
50+
{"type": "object", "properties": {}} # Add required properties field
5651
)
5752
await client.register_event_schema(
5853
"org.bing.chilling",
59-
{"type": "object"} # type: ignore
54+
{"type": "object", "properties": {}} # Add required properties field
6055
)
6156

6257
actual_event_types: set[EventType] = set()
@@ -87,12 +82,12 @@ async def test_reads_all_types_of_existing_events_and_registered_schemas(
8782
EventType(
8883
event_type="org.ban.ban",
8984
is_phantom=True,
90-
schema={"type": "object"},
85+
schema={"type": "object", "properties": {}}, # Update expected schema
9186
),
9287
EventType(
9388
event_type="org.bing.chilling",
9489
is_phantom=True,
95-
schema={"type": "object"},
90+
schema={"type": "object", "properties": {}}, # Update expected schema
9691
),
9792
}
9893

tests/test_read_events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ async def test_throws_error_for_negative_lower_bound(
355355
):
356356
client = prepared_database.with_authorization.client
357357

358-
with pytest.raises(ServerError):
358+
with pytest.raises(ClientError):
359359
async for _ in client.read_events(
360360
'/',
361361
ReadEventsOptions(

0 commit comments

Comments
 (0)