Skip to content

Commit

Permalink
core/internal/features/ocr2: parallelize subtests; extend timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 committed Oct 14, 2024
1 parent 37f3132 commit bff0c12
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
2 changes: 2 additions & 0 deletions core/capabilities/compute/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
)

func TestCache(t *testing.T) {
t.Parallel()
clock := clockwork.NewFakeClock()
tick := 1 * time.Second
timeout := 1 * time.Second
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions core/capabilities/compute/compute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
)

func Test_Compute_Start_AddsToRegistry(t *testing.T) {
t.Parallel()
log := logger.TestLogger(t)
registry := capabilities.NewRegistry(log)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand Down
22 changes: 16 additions & 6 deletions core/internal/features/ocr2/features_ocr2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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])
Expand All @@ -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)
Expand Down Expand Up @@ -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])
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tools/bin/go_core_tests
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bff0c12

Please sign in to comment.