Skip to content

Commit 682dc8c

Browse files
craig[bot]fqazi
andcommitted
Merge #157782
157782: sql: deflake TestDropWithDeletedDescriptor test r=fqazi a=fqazi Previously, TestDropWithDeletedDescriptor could flake if we wound up retrying at the KV DistSender, when communicating with the replica. This can happen under race / stress testing. To address this, this patch ensures the hook used by this test is only evaluated once. Fixes: #157063 Release note: None Co-authored-by: Faizan Qazi <[email protected]>
2 parents a1b03c0 + c871103 commit 682dc8c

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

pkg/sql/gcjob_test/gc_job_test.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
gosql "database/sql"
1111
"fmt"
1212
"strconv"
13+
"sync"
1314
"sync/atomic"
1415
"testing"
1516
"time"
@@ -609,6 +610,8 @@ func TestDropWithDeletedDescriptor(t *testing.T) {
609610
runTest := func(t *testing.T, dropIndex bool, beforeDelRange bool) {
610611
ctx, cancel := context.WithCancel(context.Background())
611612
gcJobID := make(chan jobspb.JobID)
613+
var hookShouldExecuteOnce sync.Once
614+
612615
knobs := base.TestingKnobs{
613616
JobsTestingKnobs: jobs.NewTestingKnobsWithShortIntervals(),
614617
GCJob: &sql.GCJobTestingKnobs{
@@ -645,15 +648,19 @@ func TestDropWithDeletedDescriptor(t *testing.T) {
645648
if len(k) == 0 {
646649
return nil
647650
}
648-
ch := make(chan struct{})
649-
select {
650-
case delRangeChan <- ch:
651-
case <-ctx.Done():
652-
}
653-
select {
654-
case <-ch:
655-
case <-ctx.Done():
656-
}
651+
// Disable the channel logic after the first execution in case
652+
// any retries happen in the KV dist sender.
653+
hookShouldExecuteOnce.Do(func() {
654+
ch := make(chan struct{})
655+
select {
656+
case delRangeChan <- ch:
657+
case <-ctx.Done():
658+
}
659+
select {
660+
case <-ch:
661+
case <-ctx.Done():
662+
}
663+
})
657664
return nil
658665
},
659666
}

0 commit comments

Comments
 (0)