0
0
Fork 0
mirror of https://github.com/matrix-org/dendrite synced 2024-12-15 01:13:43 +01:00
dendrite/test
kegsay ea92f80c12
Add database namespacing for unit tests (#2340)
* Add database namespacing for unit tests

Background: Running `go test ./...` will run tests in different packages concurrently.
This can be stopped or limited by using `-p 1` (no concurrency). We want concurrency,
but this causes problems when running Postgres DBs in CI. The problem is that, in CI,
we have 1x postgres server exposing 1x postgres DB, which we wipe clean at the end of
each test via `defer close()`. When tests run concurrently, calls to `close()` will
delete data/tables which other tests are currently using, causing havoc.

Fix this by:
 - Creating a database per package.
 - Namespacing the database name by a hash of the current working directory (the directory containing those `_test.go` files)

This is exactly what SQLite does, quite unintentionally, via the use of `file:dendrite_test.db`,
which dumps the file into the current working directory which is the package running the tests,
hence deleting the file is safe when running concurrently.

* Linting

* Don't create the database in a txn

* dupe db is not an error
2022-04-11 10:23:01 +01:00
..
wasm Add startup testing for Wasm Pinecone build (#1910) 2021-07-20 12:14:58 +01:00
db.go Add database namespacing for unit tests (#2340) 2022-04-11 10:23:01 +01:00
event.go syncapi: add more tests; fix more bugs (#2338) 2022-04-08 17:53:24 +01:00
room.go Add test infrastructure code for dendrite unit/integ tests (#2331) 2022-04-08 10:12:30 +01:00
user.go Add test infrastructure code for dendrite unit/integ tests (#2331) 2022-04-08 10:12:30 +01:00