Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tests/component/test_asynchronous_projections.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import timedelta
from typing import Any, Callable, Mapping, Self

import pytest_asyncio
import pytest
from logicblocks.event.testsupport import (
connection_pool,
create_table,
Expand Down Expand Up @@ -56,7 +56,7 @@
)


@pytest_asyncio.fixture
@pytest.fixture
async def open_connection_pool():
async with connection_pool(connection_settings) as pool:
yield pool
Expand All @@ -65,11 +65,11 @@ async def open_connection_pool():
class TestAsynchronousProjections:
connection_pool: AsyncConnectionPool[AsyncConnection]

@pytest_asyncio.fixture(autouse=True)
@pytest.fixture(autouse=True)
async def store_connection_pool(self, open_connection_pool):
self.connection_pool = open_connection_pool

@pytest_asyncio.fixture(autouse=True)
@pytest.fixture(autouse=True)
async def reinitialise_storage(self, open_connection_pool):
await drop_table(open_connection_pool, "events")
await drop_table(open_connection_pool, "projections")
Expand Down
7 changes: 3 additions & 4 deletions tests/component/test_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from datetime import timedelta

import pytest
import pytest_asyncio
from logicblocks.event.testsupport import (
connection_pool,
create_table,
Expand Down Expand Up @@ -52,7 +51,7 @@
)


@pytest_asyncio.fixture
@pytest.fixture
async def open_connection_pool():
async with connection_pool(connection_settings) as pool:
yield pool
Expand Down Expand Up @@ -127,11 +126,11 @@ async def cleanup(event_broker_task):
class TestEventProcessing:
connection_pool: AsyncConnectionPool[AsyncConnection]

@pytest_asyncio.fixture(autouse=True)
@pytest.fixture(autouse=True)
async def store_connection_pool(self, open_connection_pool):
self.connection_pool = open_connection_pool

@pytest_asyncio.fixture(autouse=True)
@pytest.fixture(autouse=True)
async def reinitialise_storage(self, open_connection_pool):
await drop_table(open_connection_pool, "events")
await drop_table(open_connection_pool, "projections")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import sys

import pytest
import pytest_asyncio
from logicblocks.event.testcases import (
EventSubscriberStateStoreCases,
)
Expand Down Expand Up @@ -36,7 +35,7 @@ def read_subscriber_states_query(table: str) -> abc.Query:
)


@pytest_asyncio.fixture
@pytest.fixture
async def open_connection_pool():
async with connection_pool(connection_settings) as pool:
yield pool
Expand All @@ -45,11 +44,11 @@ async def open_connection_pool():
class TestPostgresEventSubscriberStateStore(EventSubscriberStateStoreCases):
pool: AsyncConnectionPool[AsyncConnection]

@pytest_asyncio.fixture(autouse=True)
@pytest.fixture(autouse=True)
async def store_connection_pool(self, open_connection_pool):
self.pool = open_connection_pool

@pytest_asyncio.fixture(autouse=True)
@pytest.fixture(autouse=True)
async def reinitialise_storage(self, open_connection_pool):
await drop_table(open_connection_pool, "subscribers")
await create_table(open_connection_pool, "subscribers")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import sys

import pytest
import pytest_asyncio
from logicblocks.event.testcases import (
EventSubscriptionStateStoreCases,
)
Expand Down Expand Up @@ -40,7 +39,7 @@ def read_subscriber_states_query(table: str) -> abc.Query:
)


@pytest_asyncio.fixture
@pytest.fixture
async def open_connection_pool():
async with connection_pool(connection_settings) as pool:
yield pool
Expand All @@ -51,11 +50,11 @@ class TestPostgresEventSubscriptionStateStore(
):
pool: AsyncConnectionPool[AsyncConnection]

@pytest_asyncio.fixture(autouse=True)
@pytest.fixture(autouse=True)
async def store_connection_pool(self, open_connection_pool):
self.pool = open_connection_pool

@pytest_asyncio.fixture(autouse=True)
@pytest.fixture(autouse=True)
async def reinitialise_storage(self, open_connection_pool):
await drop_table(open_connection_pool, "subscriptions")
await create_table(open_connection_pool, "subscriptions")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from datetime import timedelta

import pytest
import pytest_asyncio
from logicblocks.event.testsupport import (
connection_pool,
create_table,
Expand Down Expand Up @@ -71,7 +70,7 @@ async def process_event(
self.events.append(event)


@pytest_asyncio.fixture
@pytest.fixture
async def open_connection_pool():
async with connection_pool(connection_settings) as pool:
yield pool
Expand Down Expand Up @@ -351,11 +350,11 @@ async def fail_on_event_processing_timeout():


class TestDistributedEventBrokerManySubscribersAndNodes:
@pytest_asyncio.fixture(autouse=True)
@pytest.fixture(autouse=True)
async def store_connection_pool(self, open_connection_pool):
self.connection_pool = open_connection_pool

@pytest_asyncio.fixture(autouse=True)
@pytest.fixture(autouse=True)
async def reinitialise_storage(self, open_connection_pool):
await drop_table(open_connection_pool, "events")
await drop_table(open_connection_pool, "subscribers")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import os

import pytest
import pytest_asyncio
from logicblocks.event.testcases.projection.store.harnesses import (
InMemoryProjectionStorageAdapterHarness,
PostgresProjectionStoreAdapterHarness,
ProjectionStoreAdapterHarness,
)
from logicblocks.event.testsupport import (
connection_pool,
create_table,
drop_table,
)
from logicblocks.event.testsupport.db import enable_extension
from psycopg import AsyncConnection
from psycopg_pool import AsyncConnectionPool

from logicblocks.event.persistence.postgres import ConnectionSettings

connection_settings = ConnectionSettings(
user="admin",
password="super-secret",
host=os.getenv("DB_HOST", "localhost"),
port=int(os.getenv("DB_PORT", "5432")),
dbname="some-database",
)


@pytest_asyncio.fixture(scope="session", loop_scope="session")
async def open_connection_pool():
async with connection_pool(connection_settings) as pool:
yield pool


async def _reinitialise_storage(
open_connection_pool: AsyncConnectionPool[AsyncConnection],
):
await enable_extension(open_connection_pool, "pg_trgm")
await drop_table(open_connection_pool, "projections")
await create_table(open_connection_pool, "projections")


@pytest.fixture
async def postgres_projection_store_adapter_harness(open_connection_pool):
await _reinitialise_storage(open_connection_pool)
yield PostgresProjectionStoreAdapterHarness(open_connection_pool)


@pytest.fixture
def in_memory_projection_storage_adapter_harness():
return InMemoryProjectionStorageAdapterHarness()


@pytest.fixture(
params=[
in_memory_projection_storage_adapter_harness,
postgres_projection_store_adapter_harness,
]
)
def harness(request) -> ProjectionStoreAdapterHarness:
return request.getfixturevalue(request.param.__name__)
Loading
Loading