Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 37 additions & 21 deletions tests/integration/basic_example_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, `
Expand All @@ -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, `
Expand All @@ -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)
}
})
})
})
Expand Down Expand Up @@ -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)
}
})
})

Expand Down Expand Up @@ -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)
}
})
})

Expand Down Expand Up @@ -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)
}
Comment on lines +351 to +356
Copy link

Copilot AI Oct 25, 2025

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() == nil passes but the context is canceled between line 352 and 354, row.Scan(&views) could fail with a context error. Consider checking ctx.Err() before each assertion that could be affected by context state, or move all related assertions inside a single guard.

Copilot uses AI. Check for mistakes.
})
})

Expand Down Expand Up @@ -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
Copy link

Copilot AI Oct 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to Comment 1, the row.Scan() assertion at line 398 is not guarded against context cancellation that could occur after line 391. The same race condition exists where the context could be canceled between the initial check and the scan operation. Consider re-checking ctx.Err() before line 398 or restructuring the logic to handle mid-execution cancellation.

Copilot uses AI. Check for mistakes.
})

t.Run("ScanQuery", func(t *testing.T) {
Expand Down Expand Up @@ -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)
}
})
}
Loading