Skip to content

Commit 0175610

Browse files
authored
More tests moved db folder to tests folder (#7)
1 parent 5b49846 commit 0175610

File tree

5 files changed

+55
-2
lines changed

5 files changed

+55
-2
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
run: |
3131
docker build \
3232
--build-arg POSTGRES_VERSION=${{ matrix.postgres-version }} \
33-
-t custom-postgres:latest db/
33+
-t custom-postgres:latest tests/db/
3434
env:
3535
POSTGRES_VERSION: ${{ matrix.postgres-version }}
3636

File renamed without changes.
File renamed without changes.

tests/test_decoraters.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,56 @@ async def raise_runtime_error() -> NoReturn:
7373
)
7474
assert len(exceptions) == N
7575
assert all(isinstance(exc, RuntimeError) for exc in exceptions)
76+
77+
78+
@pytest.mark.parametrize("N", (1, 2, 4, 16, 64))
79+
async def test_gready_cache_identity(
80+
N: int,
81+
pgconn: asyncpg.Connection,
82+
) -> None:
83+
statistics = collections.Counter[str]()
84+
listener = listeners.PGEventQueue()
85+
await listener.connect(
86+
pgconn,
87+
models.PGChannel("test_gready_cache_decorator_exceptions"),
88+
)
89+
90+
@decorators.cache(
91+
strategy=strategies.Gready(listener=listener),
92+
statistics_callback=lambda x: statistics.update([x]),
93+
)
94+
async def identity(x: int) -> int:
95+
return x
96+
97+
results = await asyncio.gather(*[identity(n) for n in range(N)])
98+
99+
assert sorted(results) == list(range(N))
100+
assert statistics["miss"] == N
101+
assert statistics["hit"] == 0
102+
103+
104+
@pytest.mark.parametrize("N", (1, 2, 4, 16, 64))
105+
async def test_gready_cache_sleepy(
106+
N: int,
107+
pgconn: asyncpg.Connection,
108+
) -> None:
109+
statistics = collections.Counter[str]()
110+
listener = listeners.PGEventQueue()
111+
await listener.connect(
112+
pgconn,
113+
models.PGChannel("test_gready_cache_decorator_exceptions"),
114+
)
115+
116+
@decorators.cache(
117+
strategy=strategies.Gready(listener=listener),
118+
statistics_callback=lambda x: statistics.update([x]),
119+
)
120+
async def now() -> datetime.datetime:
121+
await asyncio.sleep(0.01)
122+
return datetime.datetime.now()
123+
124+
results = await asyncio.gather(*[now() for _ in range(N)])
125+
126+
assert len(set(results)) == 1
127+
assert statistics["miss"] == 1
128+
assert statistics["hit"] == N - 1

tests/test_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async def test_2_caching(
3838
) -> None:
3939
statistics = collections.Counter[str]()
4040
listener = listeners.PGEventQueue()
41-
await listener.connect(pgconn, models.PGChannel("test_2_caching"))
41+
await listener.connect(pgconn, models.PGChannel("ch_pgcachewatch_table_change"))
4242

4343
cnt = 0
4444

0 commit comments

Comments
 (0)