Commit 405c0c5
committed
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.1 parent cc5f0e0 commit 405c0c5
85 files changed
Lines changed: 1996 additions & 2241 deletions
File tree
- .github/workflows
- internal
- cmd/testdbman
- dblist
- jobcompleter
- jobexecutor
- leadership
- maintenance
- notifier
- riverinternaltest
- riverdrivertest
- testdb
- util/dbutil
- riverdriver
- riverdatabasesql/internal/dbsqlc
- riverpgxv5
- internal/dbsqlc
- riverlog
- rivermigrate
- riverschematest
- rivertest
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 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| |||
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
93 | 70 | | |
94 | | - | |
95 | | - | |
96 | | - | |
| 71 | + | |
| 72 | + | |
97 | 73 | | |
98 | | - | |
99 | | - | |
100 | | - | |
| 74 | + | |
| 75 | + | |
101 | 76 | | |
102 | 77 | | |
103 | 78 | | |
| |||
| 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 | |
|---|---|---|---|
| |||
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