Skip to content

Commit

Permalink
Run datastore tests against multiple schemas
Browse files Browse the repository at this point in the history
We want to prove in tests that some Janus version can run safely on
multiple schema versions to make database schema migrations safer. In
this commit:

 - `aggregator_core::test_util::EphemeralDatastore` can now be
   constructed with a `max_schema_version` argument to control which
   migration scripts are applied during tests
 - `datastore::SUPPORTED_SCHEMA_VERSIONS` is now emitted by the
   `supported_schema_versions` macro, which also constructs a template
   for stamping out tests.
 - We adopt [`rstest`][1] to inject an `EphemeralDatastore` instance
   into tests in `aggregator_core::datastore::Datatore::tests`. Using
   [`rstest_reuse`][2], we can automatically stamp out versions of
   existing tests that run using multiple schema versions.

We only use this dependency injection technique in the `datastore`
module, because that should be the only module that's tightly coupled to
the database schema. We could run all tests that use a datastore this
way, at the cost of increasing overall test runtime.

[1]: https://docs.rs/rstest
[2]: https://docs.rs/rstest_reuse
  • Loading branch information
tgeoghegan committed Apr 24, 2023
1 parent efbc6ee commit ef4d30c
Show file tree
Hide file tree
Showing 6 changed files with 376 additions and 83 deletions.
221 changes: 221 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions aggregator_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ uuid = { version = "1.3.1", features = ["v4"] }

[dev-dependencies]
assert_matches = "1"
async-std = { version = "1.12.0", features = ["attributes"] }
hyper = "0.14.26"
janus_aggregator_core = { path = ".", features = ["test-util"] }
janus_core = { workspace = true, features = ["test-util"] }
rstest = "0.17.0"
rstest_reuse = "0.5.0"
serde_test = "1.0.160"
tempfile = "3.5.0"
tokio = { version = "1", features = ["test-util"] } # ensure this remains compatible with the non-dev dependency
Expand Down
Loading

0 comments on commit ef4d30c

Please sign in to comment.