Skip to content

Commit

Permalink
Replace SkipShortDB with SkipNoDB
Browse files Browse the repository at this point in the history
Instead of skipping tests which require an external db when -short flag is passed,
just skip whenever no database url is configured
  • Loading branch information
reductionista committed Dec 6, 2024
1 parent 6ecd6d1 commit 3758afb
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 55 deletions.
4 changes: 1 addition & 3 deletions core/chains/evm/log/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"

"github.com/jmoiron/sqlx"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
Expand Down Expand Up @@ -63,7 +61,7 @@ type broadcasterHelper struct {

func newBroadcasterHelper(t *testing.T, blockHeight int64, timesSubscribe int, filterLogsResult []types.Log, overridesFn func(*chainlink.Config, *chainlink.Secrets)) *broadcasterHelper {
// ensure we check before registering any mock Cleanup assertions
tests.SkipShortDB(t)
pgtest.SkipNoDB(t)

expectedCalls := mockEthClientExpectedCalls{
SubscribeFilterLogs: timesSubscribe,
Expand Down
19 changes: 9 additions & 10 deletions core/chains/evm/log/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/services/servicetest"
"github.com/smartcontractkit/chainlink-common/pkg/utils/mailbox/mailboxtest"
Expand All @@ -33,6 +31,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/internal/cltest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
)

Expand Down Expand Up @@ -69,7 +68,7 @@ func TestBroadcaster_AwaitsInitialSubscribersOnStartup(t *testing.T) {
}

func TestBroadcaster_ResubscribesOnAddOrRemoveContract(t *testing.T) {
tests.SkipShortDB(t)
pgtest.SkipNoDB(t)
const (
numConfirmations = 1
numContracts = 3
Expand Down Expand Up @@ -136,7 +135,7 @@ func TestBroadcaster_ResubscribesOnAddOrRemoveContract(t *testing.T) {
}

func TestBroadcaster_BackfillOnNodeStartAndOnReplay(t *testing.T) {
tests.SkipShortDB(t)
pgtest.SkipNoDB(t)
const (
lastStoredBlockHeight = 100
blockHeight = 125
Expand Down Expand Up @@ -194,7 +193,7 @@ func TestBroadcaster_BackfillOnNodeStartAndOnReplay(t *testing.T) {
}

func TestBroadcaster_ReplaysLogs(t *testing.T) {
tests.SkipShortDB(t)
pgtest.SkipNoDB(t)
const (
blockHeight = 10
)
Expand Down Expand Up @@ -398,7 +397,7 @@ func (helper *broadcasterHelper) simulateHeads(t *testing.T, listener, listener2
}

func TestBroadcaster_ShallowBackfillOnNodeStart(t *testing.T) {
tests.SkipShortDB(t)
pgtest.SkipNoDB(t)
const (
lastStoredBlockHeight = 100
blockHeight = 125
Expand Down Expand Up @@ -446,7 +445,7 @@ func TestBroadcaster_ShallowBackfillOnNodeStart(t *testing.T) {
}

func TestBroadcaster_BackfillInBatches(t *testing.T) {
tests.SkipShortDB(t)
pgtest.SkipNoDB(t)
const (
numConfirmations = 1
blockHeight = 120
Expand Down Expand Up @@ -504,7 +503,7 @@ func TestBroadcaster_BackfillInBatches(t *testing.T) {
}

func TestBroadcaster_BackfillALargeNumberOfLogs(t *testing.T) {
tests.SkipShortDB(t)
pgtest.SkipNoDB(t)
g := gomega.NewWithT(t)
const (
lastStoredBlockHeight = 10
Expand Down Expand Up @@ -1003,7 +1002,7 @@ func TestBroadcaster_BroadcastsAtCorrectHeightsWithHeadsEarlierThanLogs(t *testi
}

func TestBroadcaster_Register_ResubscribesToMostRecentlySeenBlock(t *testing.T) {
tests.SkipShortDB(t)
pgtest.SkipNoDB(t)
const (
backfillTimes = 1
blockHeight = 15
Expand Down Expand Up @@ -1529,7 +1528,7 @@ func requireEqualLogs(t *testing.T, expectedLogs, actualLogs []types.Log) {
}

func TestBroadcaster_BroadcastsWithZeroConfirmations(t *testing.T) {
tests.SkipShortDB(t)
pgtest.SkipNoDB(t)
gm := gomega.NewWithT(t)

ethClient := evmclimocks.NewClient(t)
Expand Down
17 changes: 8 additions & 9 deletions core/internal/cltest/cltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ import (

ocrtypes "github.com/smartcontractkit/libocr/offchainreporting/types"

"github.com/smartcontractkit/chainlink/v2/core/services/standardcapabilities"

"github.com/smartcontractkit/chainlink/v2/core/capabilities"
remotetypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/remote/types"
"github.com/smartcontractkit/chainlink/v2/core/services/llo"
p2ptypes "github.com/smartcontractkit/chainlink/v2/core/services/p2p/types"

"github.com/smartcontractkit/chainlink-common/pkg/loop"
"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
"github.com/smartcontractkit/chainlink-common/pkg/utils/mailbox"
Expand All @@ -53,6 +46,8 @@ import (
commonmocks "github.com/smartcontractkit/chainlink/v2/common/types/mocks"
"github.com/smartcontractkit/chainlink/v2/core/auth"
"github.com/smartcontractkit/chainlink/v2/core/bridges"
"github.com/smartcontractkit/chainlink/v2/core/capabilities"
remotetypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/remote/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
evmclient "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
evmclimocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client/mocks"
Expand All @@ -68,6 +63,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest"
clhttptest "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/httptest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/keystest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/logger/audit"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
Expand All @@ -83,10 +79,13 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/solkey"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/starkkey"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/vrfkey"
"github.com/smartcontractkit/chainlink/v2/core/services/llo"
p2ptypes "github.com/smartcontractkit/chainlink/v2/core/services/p2p/types"
"github.com/smartcontractkit/chainlink/v2/core/services/pg"
"github.com/smartcontractkit/chainlink/v2/core/services/pipeline"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury/wsrpc"
"github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury/wsrpc/cache"
"github.com/smartcontractkit/chainlink/v2/core/services/standardcapabilities"
"github.com/smartcontractkit/chainlink/v2/core/services/webhook"
clsessions "github.com/smartcontractkit/chainlink/v2/core/sessions"
"github.com/smartcontractkit/chainlink/v2/core/static"
Expand Down Expand Up @@ -302,7 +301,7 @@ const (
// This should only be used in full integration tests. For controller tests, see NewApplicationEVMDisabled.
func NewApplicationWithConfig(t testing.TB, cfg chainlink.GeneralConfig, flagsAndDeps ...interface{}) *TestApplication {
t.Helper()
tests.SkipShortDB(t)
pgtest.SkipNoDB(t)

ctx := testutils.Context(t)

Expand Down Expand Up @@ -521,7 +520,7 @@ func NewApplicationWithConfig(t testing.TB, cfg chainlink.GeneralConfig, flagsAn
}

func NewEthMocksWithDefaultChain(t testing.TB) (c *evmclimocks.Client) {
tests.SkipShortDB(t)
pgtest.SkipNoDB(t)
c = NewEthMocks(t)
c.On("ConfiguredChainID").Return(&FixtureChainID).Maybe()
return
Expand Down
8 changes: 8 additions & 0 deletions core/internal/testutils/pgtest/pgtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,11 @@ func MustCount(t *testing.T, db *sqlx.DB, stmt string, args ...interface{}) (cnt
require.NoError(t, db.Get(&cnt, stmt, args...))
return
}

// SkipNoDB should be called for any test which depends on an external db
// Skips test if a db url has not been configured
func SkipNoDB(tb testing.TB) {
if string(env.DatabaseURL.Get()) == "" {
tb.Skip("DB dependency")
}
}
3 changes: 1 addition & 2 deletions core/services/directrequest/delegate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/services/servicetest"
"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
"github.com/smartcontractkit/chainlink-common/pkg/utils/mailbox/mailboxtest"
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"

"github.com/smartcontractkit/chainlink/v2/core/bridges"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/log"
Expand Down Expand Up @@ -133,7 +132,7 @@ func (uni *DirectRequestUniverse) Cleanup() {
}

func TestDelegate_ServicesListenerHandleLog(t *testing.T) {
tests.SkipShortDB(t)
pgtest.SkipNoDB(t)
t.Parallel()

t.Run("Log is an OracleRequest", func(t *testing.T) {
Expand Down
24 changes: 11 additions & 13 deletions core/services/functions/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"

"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"

decryptionPlugin "github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin"

"github.com/smartcontractkit/chainlink-common/pkg/services/servicetest"
Expand Down Expand Up @@ -153,7 +151,7 @@ func packFlags(requestSizeTier int, secretSizeTier int) [32]byte {
}

func TestFunctionsListener_HandleOracleRequestV1_Success(t *testing.T) {
tests.SkipShortDB(t)
pgtest.SkipNoDB(t)
t.Parallel()

uni := NewFunctionsListenerUniverse(t, 0, 1_000_000)
Expand Down Expand Up @@ -181,7 +179,7 @@ func TestFunctionsListener_HandleOracleRequestV1_Success(t *testing.T) {
}

func TestFunctionsListener_HandleOffchainRequest_Success(t *testing.T) {
tests.SkipShortDB(t)
pgtest.SkipNoDB(t)
t.Parallel()

uni := NewFunctionsListenerUniverse(t, 0, 1_000_000)
Expand All @@ -203,7 +201,7 @@ func TestFunctionsListener_HandleOffchainRequest_Success(t *testing.T) {
}

func TestFunctionsListener_HandleOffchainRequest_Invalid(t *testing.T) {
tests.SkipShortDB(t)
pgtest.SkipNoDB(t)
t.Parallel()
uni := NewFunctionsListenerUniverse(t, 0, 1_000_000)

Expand All @@ -227,7 +225,7 @@ func TestFunctionsListener_HandleOffchainRequest_Invalid(t *testing.T) {
}

func TestFunctionsListener_HandleOffchainRequest_InternalError(t *testing.T) {
tests.SkipShortDB(t)
pgtest.SkipNoDB(t)
t.Parallel()
uni := NewFunctionsListenerUniverse(t, 0, 1_000_000)
uni.pluginORM.On("CreateRequest", mock.Anything, mock.Anything, mock.Anything).Return(nil)
Expand All @@ -247,7 +245,7 @@ func TestFunctionsListener_HandleOffchainRequest_InternalError(t *testing.T) {
}

func TestFunctionsListener_HandleOracleRequestV1_ComputationError(t *testing.T) {
tests.SkipShortDB(t)
pgtest.SkipNoDB(t)
t.Parallel()

uni := NewFunctionsListenerUniverse(t, 0, 1_000_000)
Expand Down Expand Up @@ -275,7 +273,7 @@ func TestFunctionsListener_HandleOracleRequestV1_ComputationError(t *testing.T)
}

func TestFunctionsListener_HandleOracleRequestV1_ThresholdDecryptedSecrets(t *testing.T) {
tests.SkipShortDB(t)
pgtest.SkipNoDB(t)
t.Parallel()

reqData := &struct {
Expand Down Expand Up @@ -316,7 +314,7 @@ func TestFunctionsListener_HandleOracleRequestV1_ThresholdDecryptedSecrets(t *te
}

func TestFunctionsListener_HandleOracleRequestV1_CBORTooBig(t *testing.T) {
tests.SkipShortDB(t)
pgtest.SkipNoDB(t)
t.Parallel()

uni := NewFunctionsListenerUniverse(t, 0, 1_000_000)
Expand All @@ -342,7 +340,7 @@ func TestFunctionsListener_HandleOracleRequestV1_CBORTooBig(t *testing.T) {
}

func TestFunctionsListener_ReportSourceCodeDomains(t *testing.T) {
tests.SkipShortDB(t)
pgtest.SkipNoDB(t)
t.Parallel()

uni := NewFunctionsListenerUniverse(t, 0, 1_000_000)
Expand Down Expand Up @@ -382,7 +380,7 @@ func TestFunctionsListener_ReportSourceCodeDomains(t *testing.T) {
}

func TestFunctionsListener_PruneRequests(t *testing.T) {
tests.SkipShortDB(t)
pgtest.SkipNoDB(t)
t.Parallel()

uni := NewFunctionsListenerUniverse(t, 0, 1)
Expand All @@ -397,7 +395,7 @@ func TestFunctionsListener_PruneRequests(t *testing.T) {
}

func TestFunctionsListener_TimeoutRequests(t *testing.T) {
tests.SkipShortDB(t)
pgtest.SkipNoDB(t)
t.Parallel()

uni := NewFunctionsListenerUniverse(t, 1, 0)
Expand All @@ -412,7 +410,7 @@ func TestFunctionsListener_TimeoutRequests(t *testing.T) {
}

func TestFunctionsListener_ORMDoesNotFreezeHandlersForever(t *testing.T) {
tests.SkipShortDB(t)
pgtest.SkipNoDB(t)
t.Parallel()

var ormCallExited sync.WaitGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ import (
"github.com/stretchr/testify/require"
"gopkg.in/guregu/null.v4"

"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"

"github.com/smartcontractkit/chainlink-common/pkg/types/core"

"github.com/smartcontractkit/chainlink/v2/core/bridges"
"github.com/smartcontractkit/chainlink/v2/core/internal/cltest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/configtest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest"
_ "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/job"
Expand All @@ -38,7 +37,7 @@ answer;
`

func TestAdapter_Integration(t *testing.T) {
tests.SkipShortDB(t)
pgtest.SkipNoDB(t)
ctx := testutils.Context(t)
logger := logger.TestLogger(t)
cfg := configtest.NewTestGeneralConfig(t)
Expand Down
5 changes: 2 additions & 3 deletions core/services/periodicbackup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"

"github.com/smartcontractkit/chainlink/v2/core/config"
"github.com/smartcontractkit/chainlink/v2/core/config/env"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/static"
)

func mustNewDatabaseBackup(t *testing.T, url url.URL, rootDir string, config BackupConfig) *databaseBackup {
tests.SkipShortDB(t)
pgtest.SkipNoDB(t)
b, err := NewDatabaseBackup(url, rootDir, config, logger.TestLogger(t))
require.NoError(t, err)
return b.(*databaseBackup)
Expand Down
4 changes: 1 addition & 3 deletions core/services/pg/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"

"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest"
)

Expand Down Expand Up @@ -65,7 +63,7 @@ func Test_checkVersion(t *testing.T) {
}

func Test_disallowReplica(t *testing.T) {
tests.SkipShortDB(t)
pgtest.SkipNoDB(t)
db := pgtest.NewSqlxDB(t)

_, err := db.Exec("SET session_replication_role= 'origin'")
Expand Down
Loading

0 comments on commit 3758afb

Please sign in to comment.