Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pkg/pg with dialects.go & txdb.go #910

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Conversation

reductionista
Copy link
Contributor

@reductionista reductionista commented Nov 1, 2024

NONEVM-739

Supports

smartcontractkit/chainlink#15064
smartcontractkit/chainlink-solana#921

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 (TODO: change to pkg/sqlutils/pg to match Jordan's PR]

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
Also: convert rest of panic isn't ordinary errors
tests.SkipShortDB(t)
err := RegisterTxDb(dbURL)
if err != nil {
t.Errorf("failed to register txdb dialect: %s", err.Error())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not this be a fatal error?
Otherwise caller has to check if returned db is nil.

func TestTxDBDriver(t *testing.T) {
dbURL, ok := os.LookupEnv("CL_DATABASE_URL")
require.True(t, ok, "CL_DATABASE_URL must be set")
db := NewSqlxDB(t, dbURL)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've noticed weird behavior in my PR. If two tests use db and run sequentially, second fails with conn closed error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I think I know why that's happening. I changed txdb to use the test context for queries instead of context.Background, thinking that was an improvement over what's currently in chainlink repo. But apparently that won't work--we'll have to put it back to context.Background, I guess there's just no context that would survive long enough for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants