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

Move txdb and dialects to chainlink-common/pkg/pg #15064

Merged
merged 7 commits into from
Dec 14, 2024

Conversation

reductionista
Copy link
Contributor

@reductionista reductionista commented Nov 1, 2024

NONEVM-739

Requires

smartcontractkit/chainlink-common#910

Description

This mostly just moves chainlink/core/internal/testutils/pgtest/txdb.go and chainlink/core/store/dialects/dialects.go into a new common package chainlink-common/pkg/pg, updating imports accordingly.
The purpose of this is so that it can be imported and used by chainlink-solana for unit testing Solana ORM's.

Since txdb.go was a bit of a mess, it has been cleaned up a bit.

  • The global init() function invoked on package load has been replaced with RegisterTxDb() which accepts a dbUrl as a param instead of automatically reading it from the CL_DATABASE env var. Since there are only two places in the codebase which depend on our custom txdb dialect of sql being registered, this can simply be called in both of those places (inside NewSqlxDb() and NewConnection()) instead of relying on the global init().
  • Prevents calling sql.Register() more than once if RegisterTxDb() is called more than once (calling sql.Register() more than once with the same driver name will result in an error).
  • Replaces passing of context.Background to queries with passing of a new context which gets cancelled when the db is closed. (Note: db here refers to the txdb, which is just a single connection in the lower level pg db, corresponding to the dsn passed in which is a randomly generated UUID.)
  • Corrected spelling errors

Copy link
Contributor

github-actions bot commented Nov 1, 2024

AER Report: CI Core ran successfully ✅

aer_workflow , commit

AER Report: Operator UI CI ran successfully ✅

aer_workflow , commit

@reductionista reductionista force-pushed the NONEVM-739/txdb branch 6 times, most recently from af2bde1 to b622cb9 Compare November 2, 2024 00:51
Copy link
Contributor

Flaky Test Detector for github.com/smartcontractkit/chainlink project has failed ❌

Ran new or updated tests between develop and ebe3258 (NONEVM-739/txdb).

View Flaky Detector Details | Compare Changes

Flaky Tests

Ran 2638 unique tests. Below are the tests identified as flaky, with a pass ratio lower than the 99% threshold:

TestPackage                                                       TestName                                               PassRatio  RunCount   Skipped
---------                                                         ---------                                              ---------  ---------  ---------
github.com/smartcontractkit/chainlink/v2/core/services/functions  TestFunctionsListener_ORMDoesNotFreezeHandlersForever  44%        3          false

@reductionista reductionista force-pushed the NONEVM-739/txdb branch 4 times, most recently from 0dfad7f to 3a606b8 Compare November 26, 2024 21:29
@reductionista reductionista marked this pull request as ready for review November 26, 2024 21:30
@reductionista reductionista requested review from a team and samsondav as code owners November 26, 2024 21:30
@reductionista reductionista requested a review from a team as a code owner December 5, 2024 20:46
@reductionista reductionista force-pushed the NONEVM-739/txdb branch 4 times, most recently from 29ac8fa to b602df5 Compare December 6, 2024 01:03
@smartcontractkit smartcontractkit deleted a comment from jmank88 Dec 11, 2024
@reductionista reductionista force-pushed the NONEVM-739/txdb branch 5 times, most recently from 7752eb4 to ec9e488 Compare December 12, 2024 03:20
dhaidashenko
dhaidashenko previously approved these changes Dec 12, 2024
Along with that:
- Replace dialects imports with pgcommon
- Replace testutils.Skip* with tests.Skip*
- Call RegisterTxDb from NewConnection
- Run goimports (somehow there were a few files on develop which were improperly formatted?)
While rebasing, I found that CCIP has copied the old txdb driver from
chainlink into chainlink/integrations-tests. The problem with duplicated
code is it makes it more difficult to update. Little did they know, it
had already been updated even before they copied it. So this removes the
copy and imports the newer version from chainlink-common.

The motivation for copying rather than import appears to have come from
a lint rule that enforces not being able to import anything from an
external package with "internal" in the directory name. This still
requires that the NewSqlxDB be copied, but that's just a wrapper
around the pgcommon version which reads the db url from the chainlik
toml config, which can't be accessed in chainlink-common.
@reductionista reductionista requested a review from a team as a code owner December 13, 2024 21:24
@reductionista reductionista added this pull request to the merge queue Dec 14, 2024
Merged via the queue into develop with commit d0d9e8b Dec 14, 2024
178 of 179 checks passed
@reductionista reductionista deleted the NONEVM-739/txdb branch December 14, 2024 02:15
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.

4 participants