Commit 85cc50b
authored
Full schema insertion + schema testing (#848)
* Full schema insertion + schema testing
Here, introduce a full version of schema injection as initially started
in #798, and exposing a new `Schema` option to make it configurable even
outside the test suite.
This involved fixing a lot of bugs from #798, and the only way to make
it possible to root them all out was to make full use of schemas across
the entire test suite. The original "test DB manager" system has been
replaced with a new `riverschematest.TestSchema` helper that generates a
schema for use with a test case or prefers an existing idle one that was
already generated for the same test run.
`TestSchema` runs migrations for generated schemas which also means we
don't need to use `testdbman` anymore, with tests capable of
bootstrapping themselves at run time. We reuse schemas to avoid this
extra work when possible, but migrating a new schema is also
surprisingly fast, taking up to 50ms, but getting more down to a stable
~10ms once things are warmed up. Here's a series of sample timings:
$ go test ./rivermigrate -run TestMigrator/MigrateUpDefault -test.v -count 50 | grep 'migrations ran in'
river_migrate_test.go:492: migrations ran in 45.571209ms
river_migrate_test.go:492: migrations ran in 24.642458ms
river_migrate_test.go:492: migrations ran in 16.749708ms
river_migrate_test.go:492: migrations ran in 22.970375ms
river_migrate_test.go:492: migrations ran in 16.201375ms
river_migrate_test.go:492: migrations ran in 15.727625ms
river_migrate_test.go:492: migrations ran in 13.291333ms
river_migrate_test.go:492: migrations ran in 13.680708ms
river_migrate_test.go:492: migrations ran in 14.867416ms
river_migrate_test.go:492: migrations ran in 15.631916ms
river_migrate_test.go:492: migrations ran in 13.873791ms
river_migrate_test.go:492: migrations ran in 14.8645ms
river_migrate_test.go:492: migrations ran in 14.92575ms
river_migrate_test.go:492: migrations ran in 12.541834ms
river_migrate_test.go:492: migrations ran in 14.753875ms
river_migrate_test.go:492: migrations ran in 12.694334ms
river_migrate_test.go:492: migrations ran in 13.955917ms
river_migrate_test.go:492: migrations ran in 12.126458ms
river_migrate_test.go:492: migrations ran in 14.095958ms
river_migrate_test.go:492: migrations ran in 13.273375ms
river_migrate_test.go:492: migrations ran in 13.988917ms
river_migrate_test.go:492: migrations ran in 13.141459ms
river_migrate_test.go:492: migrations ran in 12.394417ms
river_migrate_test.go:492: migrations ran in 11.539208ms
river_migrate_test.go:492: migrations ran in 11.577834ms
river_migrate_test.go:492: migrations ran in 10.883375ms
river_migrate_test.go:492: migrations ran in 10.547417ms
river_migrate_test.go:492: migrations ran in 12.330375ms
river_migrate_test.go:492: migrations ran in 11.54575ms
river_migrate_test.go:492: migrations ran in 11.437458ms
river_migrate_test.go:492: migrations ran in 10.957ms
river_migrate_test.go:492: migrations ran in 10.589083ms
river_migrate_test.go:492: migrations ran in 9.758583ms
Removal of the "test DB manager" system also means that we can ungate
test from `-p 1` because they're all able to run in parallel now. The
limiting factor I ran in is that we need to keep max pool connections
within each package's tests to a relatively modest number (I found 15
seemed to maximum success) so parallel packages don't exceed the default
Postgres configuration of 100 connections.
Something that can be kind of annoying is that in case a schema isn't
used properly somewhere in a test case (i.e. `TestSchema` is run, but
then not used), inserts/operations will go the default schema, which
will leave debris there, and that will interfere with test cases using
`TestTx` (with test DB manager, all debris would go to a different
database so you wouldn't notice). To remediate this, I've added a
cleanup hook to `TestSchema` that looks for leftovers that may have been
added to the default schema. This isn't perfect because those leftovers
may have come from another test case running in parallel or which ran
previously, but it helps to zero in on the original source of the issue.
* Use schema testing for `TestTx`, sharing one schema per set of migration lines
Here, start using a new isolated schema for test transaction invocations
rather than falling back on whatever happens to be in `river_test`. A
major benefit of this approach is that it makes migration inconsistencies
impossible so that when checking out a branch with a new migration, your
tests will always get the new migration, but then drop it when moving
back to the `master` branch.
It has the additional advantage that when alternatively running River
and River Pro tests locally pointing to the same `river_test` database,
we get the right migration lines raised for `TestTx` without having to
worry about whether Pro migrations have been made available yet or not.
We attempt to keep test transactions very efficient by only raising one
schema per package being tested (and per set of migration lines,
although this is rarely used) so we don't need to create a schema and
run migrations once per test, but rather once for _all_ tests in the
package.
Similar to `TestSchema`, `TestTx` picks up a driver so that it can use
`GetMigrationDefaultLines` to determine what migration lines a test case
is expecting to exist before running. Once again, this is mainly useful
for River Pro.
`TestTx` gets moved to the higher level `riverschematest` package
because it needs access to high level constructs like migrations, and I
rename `riverschematest` to `riverdbtest` because with test transactions
in it, its use becomes more general. I would've also moved functions
in `riversharedtest` like `DBPool` and `TestDatabaseURL` over, but
unfortunately we still need these at a lower level so that the tests in
`rivermigrate` can use them.
I removed the `riverdbtest` functionality that checks for extraneous
rows. The `public` schema no longer even exists in CI, and the check is
fairly unnecessary now that zeroing `search_path` makes it very
difficult to accidentally insert records into anything but the current
test schema.
* Inject schema to completer instead of each job being completed
Per code review feedback, instead of sending schema into the executor
and then through into each completion being made, inject it once into
the completer, then have the completer add the schema as it's completing
batches. In practice, this ends up removing a lot of schema noise, and
the job executor no longer needs to know about schema at all.1 parent cc5f0e0 commit 85cc50b
118 files changed
Lines changed: 3444 additions & 2884 deletions
File tree
- .github/workflows
- cmd/river/rivercli
- docs
- internal
- cmd/testdbman
- dblist
- jobcompleter
- jobexecutor
- leadership
- maintenance
- notifier
- riverinternaltest
- retrypolicytest
- riverdrivertest
- testdb
- util
- chanutil
- dbutil
- riverdbtest
- riverdriver
- riverdatabasesql
- internal/dbsqlc
- migration/main
- riverpgxv5
- internal/dbsqlc
- migration/main
- riverlog
- rivermigrate
- rivertest
- rivertype
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
45 | 52 | | |
46 | 53 | | |
47 | 54 | | |
| |||
62 | 69 | | |
63 | 70 | | |
64 | 71 | | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
| 72 | + | |
| 73 | + | |
73 | 74 | | |
74 | 75 | | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
| 76 | + | |
101 | 77 | | |
102 | 78 | | |
103 | 79 | | |
| |||
157 | 133 | | |
158 | 134 | | |
159 | 135 | | |
160 | | - | |
161 | | - | |
162 | | - | |
| 136 | + | |
| 137 | + | |
163 | 138 | | |
164 | | - | |
165 | | - | |
| 139 | + | |
166 | 140 | | |
167 | 141 | | |
168 | | - | |
169 | | - | |
| 142 | + | |
170 | 143 | | |
171 | 144 | | |
172 | | - | |
173 | | - | |
174 | | - | |
| 145 | + | |
175 | 146 | | |
176 | 147 | | |
177 | 148 | | |
| |||
196 | 167 | | |
197 | 168 | | |
198 | 169 | | |
199 | | - | |
200 | | - | |
| 170 | + | |
201 | 171 | | |
202 | 172 | | |
203 | 173 | | |
| |||
214 | 184 | | |
215 | 185 | | |
216 | 186 | | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
217 | 213 | | |
218 | 214 | | |
219 | 215 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
91 | 92 | | |
92 | 93 | | |
93 | 94 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| 16 | + | |
14 | 17 | | |
15 | 18 | | |
16 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| |||
0 commit comments