Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestExecContextCancel: Reduce timeout to make less flaky #879

Merged
merged 1 commit into from Nov 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions sqlite3_go18_test.go
Expand Up @@ -150,8 +150,11 @@ func TestExecContextCancel(t *testing.T) {
ts := time.Now()
initDatabase(t, db, 1000)
spent := time.Since(ts)
if spent < 100*time.Millisecond {
t.Skip("test will be too racy, as ExecContext below will be too fast.")
const minTestTime = 100 * time.Millisecond
if spent < minTestTime {
t.Skipf("test will be too racy (spent=%s < min=%s) as ExecContext below will be too fast.",
spent.String(), minTestTime.String(),
)
}

// expected to be extremely slow query
Expand All @@ -160,14 +163,17 @@ INSERT INTO test_table (key1, key_id, key2, key3, key4, key5, key6, data)
SELECT t1.key1 || t2.key1, t1.key_id || t2.key_id, t1.key2 || t2.key2, t1.key3 || t2.key3, t1.key4 || t2.key4, t1.key5 || t2.key5, t1.key6 || t2.key6, t1.data || t2.data
FROM test_table t1 LEFT OUTER JOIN test_table t2`
// expect query above take ~ same time as setup above
ctx, cancel := context.WithTimeout(context.Background(), spent/2)
// This is racy: the context must be valid so sql/db.ExecContext calls the sqlite3 driver.
// It starts the query, the context expires, then calls sqlite3_interrupt
ctx, cancel := context.WithTimeout(context.Background(), minTestTime/2)
defer cancel()
ts = time.Now()
r, err := db.ExecContext(ctx, q)
// racy check
if r != nil {
n, err := r.RowsAffected()
t.Log(n, err, time.Since(ts))
t.Logf("query should not have succeeded: rows=%d; err=%v; duration=%s",
n, err, time.Since(ts).String())
}
if err != context.DeadlineExceeded {
t.Fatal(err, ctx.Err())
Expand Down