Skip to content

Commit

Permalink
Merge pull request #8271 from smartcontractkit/BCF-1997
Browse files Browse the repository at this point in the history
Updated the 'drop dangling databases' methodology
  • Loading branch information
hans-kessock authored Jan 18, 2023
2 parents abe1706 + 425aaf2 commit 74116d9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ go generate ./...

```bash
export DATABASE_URL=postgresql://127.0.0.1:5432/chainlink_test?sslmode=disable
export CL_DATABASE_URL=$DATABASE_URL
```

Note: Other environment variables should not be set for all tests to pass
Expand Down
3 changes: 2 additions & 1 deletion core/cmd/local_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const ownerPermsMask = os.FileMode(0700)
// PristineDBName is a clean copy of test DB with migrations.
// Used by heavyweight.FullTestDB* functions.
const PristineDBName = "chainlink_test_pristine"
const TestDBNamePrefix = "chainlink_test_"

// RunNode starts the Chainlink core.
func (cli *Client) RunNode(c *clipkg.Context) error {
Expand Down Expand Up @@ -555,7 +556,7 @@ func dropDanglingTestDBs(lggr logger.Logger, db *sqlx.DB) (err error) {
}()
}
for _, dbname := range dbs {
if strings.HasPrefix(dbname, "chainlink_test_") && !strings.HasSuffix(dbname, "_pristine") {
if strings.HasPrefix(dbname, TestDBNamePrefix) && !strings.HasSuffix(dbname, "_pristine") {
ch <- dbname
}
}
Expand Down
3 changes: 2 additions & 1 deletion core/internal/cltest/heavyweight/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ func dropAndCreateThrowawayTestDB(parsed url.URL, postfix string, empty bool) (s
return "", errors.New("path missing from database URL")
}

dbname := fmt.Sprintf("%s_%s", parsed.Path[1:], postfix)
// Match the naming schema that our dangling DB cleanup methods expect
dbname := cmd.TestDBNamePrefix + postfix
if l := len(dbname); l > 63 {
return "", fmt.Errorf("dbname %v too long (%d), max is 63 bytes. Try a shorter postfix", dbname, l)
}
Expand Down
3 changes: 2 additions & 1 deletion core/services/fluxmonitorv2/flux_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/smartcontractkit/chainlink/core/chains/evm/log"
logmocks "github.com/smartcontractkit/chainlink/core/chains/evm/log/mocks"
"github.com/smartcontractkit/chainlink/core/chains/evm/txmgr"
"github.com/smartcontractkit/chainlink/core/cmd"
"github.com/smartcontractkit/chainlink/core/gethwrappers/generated/flux_aggregator_wrapper"
"github.com/smartcontractkit/chainlink/core/internal/cltest"
"github.com/smartcontractkit/chainlink/core/internal/cltest/heavyweight"
Expand Down Expand Up @@ -894,7 +895,7 @@ func TestFluxMonitor_HibernationTickerFiresMultipleTimes(t *testing.T) {
// chainlink_test_TestFluxMonitor_HibernationIsEnteredAndRetryTickerStopped
// 63 bytes is max and chainlink_test_ takes up 15, plus 4 for a random hex suffix.
func dbName(s string) string {
diff := len("chainlink_test_") + len("_FFF")
diff := len(cmd.TestDBNamePrefix) + len("_FFF")
if len(s) <= diff {
return strings.ReplaceAll(strings.ToLower(s), "/", "")
}
Expand Down

0 comments on commit 74116d9

Please sign in to comment.