Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
79628: logictest: deflake tests with async statements r=AlexTalks a=AlexTalks

While async statements in logictests were introduced in cockroachdb#79010, in some
cases tests with async statements would fail due to a race condition.
This is fixed by updating the logic such that when an async statement is
issued, the goroutine running that statement is ensured to have started
before execution continues to other lines in the test.

Fixes cockroachdb#79565.

Release note: None

Release Justification: Testing change only.

Co-authored-by: Alex Sarkesian <[email protected]>
  • Loading branch information
craig[bot] and AlexTalks committed Apr 8, 2022
2 parents 7a97bdd + ea00dcc commit 51aed4d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/sql/logictest/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -3336,11 +3336,14 @@ func (t *logicTest) execStatement(stmt logicStatement) (bool, error) {
}
t.pendingStatements[stmt.statementName] = pending

startedChan := make(chan struct{})
go func() {
startedChan <- struct{}{}
res, err := t.db.Exec(execSQL)
pending.resultChan <- pendingExecResult{execSQL, res, err}
}()

<-startedChan
return true, nil
}

Expand Down

0 comments on commit 51aed4d

Please sign in to comment.