YongGoose opened a new issue, #1034:
URL: https://github.com/apache/burr/issues/1034

   The Redis and PostgreSQL persister integration tests leave their data 
behind, so running them a second time against the same databases fails 22 
tests. CI doesn't hit this because every job starts fresh service containers, 
but it breaks the usual local loop of keeping the databases up and re-running 
the tests.
   
   # Current behavior
   
   Against fresh Postgres/MongoDB/Redis instances, 
`tests/integrations/persisters` passes (68 passed). Every later run against the 
same databases fails the same 22 tests: 13 in `test_b_redis.py` and 9 in 
`test_postgresql.py`.
   
   ## Stack Traces
   
   ```
   psycopg2.errors.UniqueViolation: duplicate key value violates unique 
constraint "testtable_pkey"
   asyncpg.exceptions.UniqueViolationError: duplicate key value violates unique 
constraint "testtable_async_pkey"
   ValueError: partition_key:app_id:sequence_id[pk:app_id:1] already exists.
   ```
   
   ## Steps to replicate behavior
   1. Start the same services the CI persister job uses:
      ```
      docker run -d --rm --name burr-pg -e POSTGRES_PASSWORD=postgres -p 
5432:5432 postgres:15
      docker run -d --rm --name burr-mongo -p 27017:27017 mongo:7.0
      docker run -d --rm --name burr-redis -p 6379:6379 redis:7
      ```
   2. `BURR_CI_INTEGRATION_TESTS=true pytest tests/integrations/persisters`: 68 
passed
   3. Run the same command again: 22 failed, 46 passed (and the same on every 
run after that)
   
   After one clean run, Redis holds 25 keys (15 in db 0, 10 in db 1) and 
Postgres holds 15 rows (`testtable`: 8, `testtable_async`: 7). MongoDB is empty.
   
   ## Library & System Information
   burr `main` at 36e3ff3 (0.43.0). Python 3.12 on macOS, and Python 3.12 in a 
linux/arm64 container. postgres:15, mongo:7.0 and redis:7, the same images CI 
uses.
   
   # Expected behavior
   
   The tests clean up after themselves, so they pass on every run, not only the 
first.
   
   # Additional context
   
   The persisters intentionally reject saving a step that already exists: Redis 
and MongoDB raise `ValueError`, and Postgres hits the primary key. The tests 
use fixed keys such as `("pk", "app_id", 1)`.
   
   - The MongoDB fixture tears down with `persister.collection.drop()`, which 
is why it isn't affected.
   - The Redis and Postgres fixtures only call `persister.cleanup()`, which 
just closes the connection (`b_redis.py`, `b_psycopg2.py`, `b_asyncpg.py`), so 
their data stays.
   - `test_redis_persister_class_backwards_compatible` doesn't use a fixture 
and never cleans up either.
   
   A fix shouldn't use `FLUSHDB`: the Redis tests use db 0, which is Redis' 
default and may hold a developer's own data. I'll open a PR for this.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to