Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pkg/pg with dialects.go & txdb.go (#910)
* Add pkg/pg with dialects.go & txdb.go Neither of these were in the actual pg package in chainlink repo. dialects.go came from core/store/dialects and txdb.go from core/internal/testutils/pgtest, but neither of these seem like they deserve their own package in chainlink-common--we can lump all the postgres specific common utilities under pkg/pg * Add TestTxDBDriver, NewSqlxDB, SkipShort, SkipShortDB and SkipFlakey * Add idempotency test of RegisterTxDb * Create ctx from testing context, instead of using context.Background * Only abort tx's when last connection is closed Also: convert rest of panic isn't ordinary errors * go mod tidy * Split abort channel into one per connection object All txdb connections share the same underlying connection to the postgres db. Calling NewSqlxDB() or NewConnection() with dialect=txdb doesn't create a new pg connection, it just creates a new tx with BEGIN. Closing the connection with db.Close() issues ROLLBACK. Both NewSqlxDB() and NewConneciton() choose random UUID's for their dsn string, so we shouldn't have a case where the same dsn is opened more than once. If that did happen, then these two different txdb "connections" would be sharing the same transaction which would mean closing the abort channel due to a query sent over one of them would affect the other. Hopefully that's not a problem? If it is I think our only option will be to go back to using context.Background for all queries. Before this commit, there was only one abort channel for the entire txdb driver meaning that even two entirely different connections opened with different dsn's could interfere with each other's queries. This should fix that case, which is presumably the only case we care about. Since each dsn corresponds to a different call to NewSqlxDB() and the UUID's are generated randomly, there should no longer be a conflict. Each txdb connection will have its own abort channel. * Errorf -> Fatalf on failure to register txdb driver * Add in-memory DataSource using go-duckdb * Fall back to testing txdb with in-memory backed db if CL_DATABASE_URL is not set This allows us to test most of it in CI, and all locally * Fix imports & fmt.Sprintf -> t.Log * Add concurrency test for RegisterTxDb() * Fix race condition This showed up in some of the unit tests in the linked PR in chainlink repo * Remove pg.SkipDB(), add DbUrlOrInMemory() * pkg/pg -> pkg/sqlutil/pg * NewSqlxDB -> NewTestDB, DbUrlOrInMemory -> TestURL
- Loading branch information