Documentation
¶
Overview ¶
Package testsupport holds helpers the test suites of several packages need from each other. It is imported only by tests.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LockSettings ¶
LockSettings gives a test the global settings table to itself: it serialises the tests that write it, and when the test ends it puts the table back as it found it, then releases the lock. Every test that writes a settings row must take it, even one writing a key of its own: putting the table back drops any row written meanwhile by a test that holds no lock.
`go test ./...` runs packages in parallel and they all point at one database, so three packages flipping maintenance_features_enabled were stepping on each other: a test would set the switch on, and another package would set it off halfway through, failing the first one on a switch it never touched. Nothing in the product is wrong there — the setting is global by design — so the serialisation belongs here rather than in a per-test workaround. Putting the table back keeps a test from depending on what an earlier one left behind.
The lock is taken on a connection of its own: an advisory lock lives on a session, and a pooled query may land on any connection. The same connection puts the table back, so that still works after the test's deferred Close of its store. Taking it again in the same test does nothing; a subtest is a test of its own, and waits on its parent's lock. The lock is polled for rather than waited on in one statement, which the driver's 10 second read timeout would cut short.
func SetSetting ¶ added in v0.1.15
SetSetting gives one settings row a value for the length of a test, so the test does not rely on another one having left it so. It takes LockSettings, which puts the row back when the test ends; a test may call it for several rows.
It writes the row directly, which suits plain settings only: secret ones are stored encrypted by the store.
Types ¶
This section is empty.