Skip to content

Commit

Permalink
Merge #38507
Browse files Browse the repository at this point in the history
38507: exec: fix TestHashRouterCancellation r=jordanlewis a=asubiotto

testing.T was being used in a goroutine and hitting a flaky failure
condition (getting back "query canceled" instead of "context canceled").
Check has been moved to main goroutine and relaxed.

Release note: None

Fixes #38491

Co-authored-by: Alfonso Subiotto Marqués <alfonso@cockroachlabs.com>
  • Loading branch information
craig[bot] and asubiotto committed Jun 27, 2019
2 parents 90841a6 + 2bfd63e commit 6ad3692
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions pkg/sql/exec/routers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"testing"
"time"

"github.com/cockroachdb/cockroach/pkg/sql/distsqlpb"
"github.com/cockroachdb/cockroach/pkg/sql/exec/coldata"
"github.com/cockroachdb/cockroach/pkg/sql/exec/types"
"github.com/cockroachdb/cockroach/pkg/testutils"
Expand Down Expand Up @@ -568,13 +569,11 @@ func TestHashRouterCancellation(t *testing.T) {
}()
}

doneCh := make(chan struct{})
routerMeta := make(chan []distsqlpb.ProducerMetadata)
go func() {
r.Run(ctx)
meta := r.DrainMeta(ctx)
require.Equal(t, 1, len(meta))
require.True(t, testutils.IsError(meta[0].Err, "context canceled"), meta[0].Err)
close(doneCh)
routerMeta <- r.DrainMeta(ctx)
close(routerMeta)
}()

time.Sleep(time.Millisecond)
Expand All @@ -585,12 +584,14 @@ func TestHashRouterCancellation(t *testing.T) {
}
}
select {
case <-doneCh:
case <-routerMeta:
t.Fatal("hash router goroutine unexpectedly done")
default:
}
cancel()
<-doneCh
meta := <-routerMeta
require.Equal(t, 1, len(meta))
require.True(t, testutils.IsError(meta[0].Err, "canceled"), meta[0].Err)

if numCancels != int64(len(outputs)) {
t.Fatalf("expected %d canceled outputs, actual %d", len(outputs), numCancels)
Expand Down

0 comments on commit 6ad3692

Please sign in to comment.