mi: limit the CIM_DataFile cancellation test to one directory (#2752)

Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
Jan-Otto Kröpke
2026-10-16 11:47:44 +02:00
committed by GitHub
parent 667200f757
commit b3500f7aef
2 changed files with 12 additions and 3 deletions
+7
View File
@@ -63,5 +63,12 @@ results never look complete. A context that is done after the final result
(`complete`, set under `mu`) does not fail a query that has nothing left to
hand over.
Tests that need a slow query must bound the work it causes. Cancelling an
operation may end it only on the client: providers such as CIMWin32
(`CIM_DataFile`) keep enumerating in WmiPrvSE. `CIM_DataFile` for a whole drive
kept the CI runner busy for minutes after the Go tests, which slowed every
later step and made the end-to-end `/metrics` request time out. Restrict such
queries to one directory.
Run `CGO_ENABLED=1 go test -race` (gcc from w64devkit) and a
`-gcflags=all=-d=checkptr` run for changes in this package.
+5 -3
View File
@@ -327,9 +327,11 @@ func Test_MI_QueryContext_CancelDuringQuery(t *testing.T) {
})
t.Run("QueryContext", func(t *testing.T) {
// CIM_DataFile enumerates every file of the drive, which takes far
// longer than the context.
slowQuery, err := mi.NewQuery("SELECT Name FROM CIM_DataFile WHERE Drive = 'C:'")
// CIM_DataFile is slow, so the query outlives the context. Cancel
// does not stop the CIMWin32 provider in WmiPrvSE: it finishes the
// enumeration on its own. Keep the query to one directory; a whole
// drive keeps the runner busy for minutes after the test.
slowQuery, err := mi.NewQuery(`SELECT Name FROM CIM_DataFile WHERE Drive = 'C:' AND Path = '\\Windows\\System32\\'`)
require.NoError(t, err)
ctx, cancel := context.WithTimeout(t.Context(), 100*time.Millisecond)