Skip to content

Commit

Permalink
Merge #137334
Browse files Browse the repository at this point in the history
137334: ccl/changefeedccl/cdcevent: Fix flake in TestEventColumnOrderingWithSchemaChanges r=spilchen a=spilchen

This commit addresses a test flake in TestEventColumnOrderingWithSchemaChanges. The test relies on the SCHEMA CHANGE GC job, which triggers the RangeFeedDeleteRange event. Since this job runs asynchronously, delays in its execution occasionally caused the test to fail.

To mitigate this, the test has been updated to ensure the job starts more promptly. Additionally, debugging aids have been added to facilitate future investigations if the test fails again.

Epic: None
Closes #136371 
Release note: None

Co-authored-by: Matt Spilchen <[email protected]>
  • Loading branch information
craig[bot] and spilchen committed Dec 12, 2024
2 parents 43fe07f + cffa888 commit 497656e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/ccl/changefeedccl/cdcevent/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ go_test(
"//pkg/sql/schemachanger/scplan",
"//pkg/sql/sem/eval",
"//pkg/sql/sem/tree",
"//pkg/sql/sqltestutils",
"//pkg/sql/types",
"//pkg/testutils/serverutils",
"//pkg/testutils/skip",
Expand Down
16 changes: 14 additions & 2 deletions pkg/ccl/changefeedccl/cdcevent/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scplan"
"github.com/cockroachdb/cockroach/pkg/sql/sem/eval"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sqltestutils"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
"github.com/cockroachdb/cockroach/pkg/testutils/skip"
Expand Down Expand Up @@ -595,7 +596,12 @@ func TestEventColumnOrderingWithSchemaChanges(t *testing.T) {
kvserver.RangefeedEnabled.Override(ctx, &l.ClusterSettings().SV, true)
}

// Be aggressive with the SCHEMA CHANGE GC job. For tests involving column
// rewrites, this job must run for the tests to succeed. Its execution
// triggers RangeFeedDeleteRange events.
sqlDB := sqlutils.MakeSQLRunner(db)
defer sqltestutils.DisableGCTTLStrictEnforcement(t, db)()
sqlDB.Exec(t, "SET CLUSTER SETTING jobs.registry.interval.adopt='1s'")

type decodeExpectation struct {
expectUnwatchedErr bool
Expand Down Expand Up @@ -730,8 +736,9 @@ func TestEventColumnOrderingWithSchemaChanges(t *testing.T) {
},
} {
t.Run(tc.testName, func(t *testing.T) {
sqlDB.Exec(t, `
CREATE TABLE foo (
sqlDB.ExecMultiple(t,
`DROP TABLE IF EXISTS foo`,
`CREATE TABLE foo (
i INT,
j INT,
a STRING,
Expand All @@ -748,6 +755,9 @@ func TestEventColumnOrderingWithSchemaChanges(t *testing.T) {
popRow, cleanup := cdctest.MakeRangeFeedValueReaderExtended(t, s.ExecutorConfig(), tableDesc)
defer cleanup()

_, err := sqltestutils.AddImmediateGCZoneConfig(db, tableDesc.GetID())
require.NoError(t, err)

targetType := jobspb.ChangefeedTargetSpecification_EACH_FAMILY
if tc.familyName != "" {
targetType = jobspb.ChangefeedTargetSpecification_COLUMN_FAMILY
Expand All @@ -769,8 +779,10 @@ func TestEventColumnOrderingWithSchemaChanges(t *testing.T) {
require.NoError(t, err)

expectedEvents := len(tc.expectMainFamily) + len(tc.expectECFamily)
log.Infof(ctx, "expectedEvents: %d\n", expectedEvents)
for i := 0; i < expectedEvents; i++ {
v, deleteRange := popRow(t)
log.Infof(ctx, "event[%d]: v=%+v, deleteRange=%+v", i, v, deleteRange)

if deleteRange != nil {
// Should not see a RangeFeedValue and a RangeFeedDeleteRange
Expand Down

0 comments on commit 497656e

Please sign in to comment.