-
Couldn't load subscription status.
- Fork 104
Fix flaky TestBasicExampleQuery by handling context cancellation #1907
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -144,7 +144,9 @@ func TestBasicExampleQuery(sourceTest *testing.T) { //nolint:gocyclo | |
| PRIMARY KEY(series_id) | ||
| )`, | ||
| ) | ||
| require.NoError(t, err) | ||
| if ctx.Err() == nil { | ||
| require.NoError(t, err) | ||
| } | ||
| }) | ||
| t.Run("seasons", func(t *testing.T) { | ||
| err := db.Query().Exec(ctx, ` | ||
|
|
@@ -162,7 +164,9 @@ func TestBasicExampleQuery(sourceTest *testing.T) { //nolint:gocyclo | |
| PRIMARY KEY(series_id,season_id) | ||
| )`, | ||
| ) | ||
| require.NoError(t, err) | ||
| if ctx.Err() == nil { | ||
| require.NoError(t, err) | ||
| } | ||
| }) | ||
| t.Run("episodes", func(t *testing.T) { | ||
| err := db.Query().Exec(ctx, ` | ||
|
|
@@ -181,7 +185,9 @@ func TestBasicExampleQuery(sourceTest *testing.T) { //nolint:gocyclo | |
| PRIMARY KEY(series_id,season_id,episode_id) | ||
| )`, | ||
| ) | ||
| require.NoError(t, err) | ||
| if ctx.Err() == nil { | ||
| require.NoError(t, err) | ||
| } | ||
| }) | ||
| }) | ||
| }) | ||
|
|
@@ -246,7 +252,9 @@ func TestBasicExampleQuery(sourceTest *testing.T) { //nolint:gocyclo | |
| ), | ||
| query.WithIdempotent(), | ||
| ) | ||
| require.NoError(t, err) | ||
| if ctx.Err() == nil { | ||
| require.NoError(t, err) | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
|
|
@@ -310,7 +318,9 @@ func TestBasicExampleQuery(sourceTest *testing.T) { //nolint:gocyclo | |
| }, | ||
| query.WithIdempotent(), | ||
| ) | ||
| require.NoError(t, err) | ||
| if ctx.Err() == nil { | ||
| require.NoError(t, err) | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
|
|
@@ -338,10 +348,12 @@ func TestBasicExampleQuery(sourceTest *testing.T) { //nolint:gocyclo | |
| Build(), | ||
| ), | ||
| ) | ||
| require.NoError(t, err) | ||
| var views uint64 | ||
| require.NoError(t, row.Scan(&views)) | ||
| require.EqualValues(t, 1, views) | ||
| if ctx.Err() == nil { | ||
| require.NoError(t, err) | ||
| var views uint64 | ||
| require.NoError(t, row.Scan(&views)) | ||
| require.EqualValues(t, 1, views) | ||
| } | ||
| }) | ||
| }) | ||
|
|
||
|
|
@@ -376,17 +388,19 @@ func TestBasicExampleQuery(sourceTest *testing.T) { //nolint:gocyclo | |
| query.WithParameters(ydb.ParamsBuilder().Param("$seriesID").Uint64(1).Build()), | ||
| query.WithTxControl(query.SnapshotReadOnlyTxControl()), | ||
| ) | ||
| require.NoError(t, err) | ||
| var ( | ||
| id *uint64 | ||
| title *string | ||
| date *time.Time | ||
| ) | ||
| require.NoError(t, row.Scan(&id, &title, &date)) | ||
| t.Logf( | ||
| " > %d %s %s\n", | ||
| *id, *title, *date, | ||
| ) | ||
| if ctx.Err() == nil { | ||
| require.NoError(t, err) | ||
| var ( | ||
| id *uint64 | ||
| title *string | ||
| date *time.Time | ||
| ) | ||
| require.NoError(t, row.Scan(&id, &title, &date)) | ||
| t.Logf( | ||
| " > %d %s %s\n", | ||
| *id, *title, *date, | ||
| ) | ||
| } | ||
|
Comment on lines
+391
to
+403
|
||
| }) | ||
|
|
||
| t.Run("ScanQuery", func(t *testing.T) { | ||
|
|
@@ -438,6 +452,8 @@ func TestBasicExampleQuery(sourceTest *testing.T) { //nolint:gocyclo | |
|
|
||
| return nil | ||
| }, query.WithIdempotent()) | ||
| require.NoError(t, err) | ||
| if ctx.Err() == nil { | ||
| require.NoError(t, err) | ||
| } | ||
| }) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assertions at lines 354-355 should also be guarded against context cancellation. If
ctx.Err() == nilpasses but the context is canceled between line 352 and 354,row.Scan(&views)could fail with a context error. Consider checkingctx.Err()before each assertion that could be affected by context state, or move all related assertions inside a single guard.