From bff0c1268c43c218b4daa30cf080abdf689b7914 Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Mon, 14 Oct 2024 07:28:34 -0500 Subject: [PATCH] core/internal/features/ocr2: parallelize subtests; extend timeouts --- core/capabilities/compute/cache_test.go | 2 ++ core/capabilities/compute/compute_test.go | 4 ++++ .../features/ocr2/features_ocr2_test.go | 22 ++++++++++++++----- tools/bin/go_core_tests | 2 +- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/core/capabilities/compute/cache_test.go b/core/capabilities/compute/cache_test.go index 358eb37f4e3..3b38cc23001 100644 --- a/core/capabilities/compute/cache_test.go +++ b/core/capabilities/compute/cache_test.go @@ -21,6 +21,7 @@ const ( ) func TestCache(t *testing.T) { + t.Parallel() clock := clockwork.NewFakeClock() tick := 1 * time.Second timeout := 1 * time.Second @@ -55,6 +56,7 @@ func TestCache(t *testing.T) { } func TestCache_EvictAfterSize(t *testing.T) { + t.Parallel() ctx := tests.Context(t) clock := clockwork.NewFakeClock() tick := 1 * time.Second diff --git a/core/capabilities/compute/compute_test.go b/core/capabilities/compute/compute_test.go index 39e2b12150b..12dbfaccee5 100644 --- a/core/capabilities/compute/compute_test.go +++ b/core/capabilities/compute/compute_test.go @@ -17,6 +17,7 @@ import ( ) func Test_Compute_Start_AddsToRegistry(t *testing.T) { + t.Parallel() log := logger.TestLogger(t) registry := capabilities.NewRegistry(log) @@ -31,6 +32,7 @@ func Test_Compute_Start_AddsToRegistry(t *testing.T) { } func Test_Compute_Execute_MissingConfig(t *testing.T) { + t.Parallel() log := logger.TestLogger(t) registry := capabilities.NewRegistry(log) @@ -57,6 +59,7 @@ func Test_Compute_Execute_MissingConfig(t *testing.T) { } func Test_Compute_Execute_MissingBinary(t *testing.T) { + t.Parallel() log := logger.TestLogger(t) registry := capabilities.NewRegistry(log) @@ -81,6 +84,7 @@ func Test_Compute_Execute_MissingBinary(t *testing.T) { } func Test_Compute_Execute(t *testing.T) { + t.Parallel() log := logger.TestLogger(t) registry := capabilities.NewRegistry(log) diff --git a/core/internal/features/ocr2/features_ocr2_test.go b/core/internal/features/ocr2/features_ocr2_test.go index 9160310261f..5ab334ee91e 100644 --- a/core/internal/features/ocr2/features_ocr2_test.go +++ b/core/internal/features/ocr2/features_ocr2_test.go @@ -26,6 +26,7 @@ import ( "github.com/onsi/gomega" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/zap" "github.com/smartcontractkit/libocr/commontypes" "github.com/smartcontractkit/libocr/gethwrappers2/ocr2aggregator" @@ -35,6 +36,8 @@ import ( ocrtypes2 "github.com/smartcontractkit/libocr/offchainreporting2plus/types" commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" + "github.com/smartcontractkit/chainlink/v2/core/config/toml" "github.com/smartcontractkit/chainlink/v2/core/bridges" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets" @@ -114,6 +117,7 @@ func setupNodeOCR2( ctx := testutils.Context(t) p2pKey := keystest.NewP2PKeyV2(t) config, _ := heavyweight.FullTestDBV2(t, func(c *chainlink.Config, s *chainlink.Secrets) { + c.Log.Level = ptr[toml.LogLevel](toml.LogLevel(zap.WarnLevel)) c.Insecure.OCRDevelopmentMode = ptr(true) // Disables ocr spec validation so we can have fast polling for the test. c.Feature.LogPoller = ptr(true) @@ -203,9 +207,11 @@ func testIntegration_OCR2(t *testing.T) { } { test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() owner, b, ocrContractAddress, ocrContract := setupOCR2Contracts(t) lggr := logger.TestLogger(t) + lggr.SetLogLevel(zap.WarnLevel) bootstrapNodePort := freeport.GetOne(t) bootstrapNode := setupNodeOCR2(t, owner, bootstrapNodePort, false /* useForwarders */, b, nil) @@ -550,7 +556,7 @@ updateInterval = "1m" completedRuns, err2 := apps[ic].JobORM().FindPipelineRunIDsByJobID(ctx, jids[ic], 0, 1000) require.NoError(t, err2) // Want at least 2 runs so we see all the metadata. - pr := cltest.WaitForPipelineComplete(t, ic, jids[ic], len(completedRuns)+2, 7, apps[ic].JobORM(), 2*time.Minute, 5*time.Second) + pr := cltest.WaitForPipelineComplete(t, ic, jids[ic], len(completedRuns)+2, 7, apps[ic].JobORM(), tests.WaitTimeout(t), 5*time.Second) jb, err2 := pr[0].Outputs.MarshalJSON() require.NoError(t, err2) assert.Equal(t, []byte(fmt.Sprintf("[\"%d\"]", retVal*ic)), jb, "pr[0] %+v pr[1] %+v", pr[0], pr[1]) @@ -561,11 +567,13 @@ updateInterval = "1m" // Trail #1: 4 oracles reporting 0, 10, 20, 30. Answer should be 20 (results[4/2]). // Trial #2: 4 oracles reporting 0, 20, 40, 60. Answer should be 40 (results[4/2]). - gomega.NewGomegaWithT(t).Eventually(func() string { + if !gomega.NewGomegaWithT(t).Eventually(func() string { answer, err2 := ocrContract.LatestAnswer(nil) require.NoError(t, err2) return answer.String() - }, 1*time.Minute, 200*time.Millisecond).Should(gomega.Equal(fmt.Sprintf("%d", 2*retVal))) + }, tests.WaitTimeout(t), 200*time.Millisecond).Should(gomega.Equal(fmt.Sprintf("%d", 2*retVal))) { + t.Fatal() + } for _, app := range apps { jobs, _, err2 := app.JobORM().FindJobs(ctx, 0, 1000) @@ -876,7 +884,7 @@ updateInterval = "1m" go func() { defer wg.Done() // Want at least 2 runs so we see all the metadata. - pr := cltest.WaitForPipelineComplete(t, ic, jids[ic], 2, 7, apps[ic].JobORM(), 2*time.Minute, 5*time.Second) + pr := cltest.WaitForPipelineComplete(t, ic, jids[ic], 2, 7, apps[ic].JobORM(), tests.WaitTimeout(t), 5*time.Second) jb, err := pr[0].Outputs.MarshalJSON() require.NoError(t, err) assert.Equal(t, []byte(fmt.Sprintf("[\"%d\"]", 10*ic)), jb, "pr[0] %+v pr[1] %+v", pr[0], pr[1]) @@ -886,11 +894,13 @@ updateInterval = "1m" wg.Wait() // 4 oracles reporting 0, 10, 20, 30. Answer should be 20 (results[4/2]). - gomega.NewGomegaWithT(t).Eventually(func() string { + if !gomega.NewGomegaWithT(t).Eventually(func() string { answer, err := ocrContract.LatestAnswer(nil) require.NoError(t, err) return answer.String() - }, 1*time.Minute, 200*time.Millisecond).Should(gomega.Equal("20")) + }, tests.WaitTimeout(t), 200*time.Millisecond).Should(gomega.Equal("20")) { + t.Fatal() + } for _, app := range apps { jobs, _, err := app.JobORM().FindJobs(ctx, 0, 1000) diff --git a/tools/bin/go_core_tests b/tools/bin/go_core_tests index f7c1dfaf231..0b68bc7700d 100755 --- a/tools/bin/go_core_tests +++ b/tools/bin/go_core_tests @@ -19,7 +19,7 @@ use_tee() { cat > "$@" fi } -go test -json -ldflags "$GO_LDFLAGS" -tags integration $TEST_FLAGS -covermode=atomic -coverpkg=./... -coverprofile=coverage.txt $1 | use_tee $OUTPUT_FILE +go test -timeout 15m -json -ldflags "$GO_LDFLAGS" -tags integration $TEST_FLAGS -covermode=atomic -coverpkg=./... -coverprofile=coverage.txt $1 | use_tee $OUTPUT_FILE EXITCODE=${PIPESTATUS[0]} # Assert no known sensitive strings present in test logger output