Skip to content

Commit 4e3a39d

Browse files
committed
ctx best practices.
1 parent 7e9fa29 commit 4e3a39d

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

conformance/conformance.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ func RunConformance(t *testing.T) {
191191
// RunConformanceWithOptions runs the Inference Extension conformance tests with specific options.
192192
func RunConformanceWithOptions(t *testing.T, opts confsuite.ConformanceOptions) {
193193
t.Helper()
194+
ctx := context.Background()
195+
194196
t.Logf("Running Inference Extension conformance tests with GatewayClass %s", opts.GatewayClassName)
195197
logDebugf(t, opts.Debug, "RunConformanceWithOptions: BaseManifests path being used by opts: %q", opts.BaseManifests)
196198

@@ -204,7 +206,7 @@ func RunConformanceWithOptions(t *testing.T, opts confsuite.ConformanceOptions)
204206
require.NoError(t, err, "error initializing conformance suite")
205207

206208
installedCRDs := &apiextensionsv1.CustomResourceDefinitionList{}
207-
err = opts.Client.List(context.TODO(), installedCRDs)
209+
err = opts.Client.List(ctx, installedCRDs)
208210
require.NoError(t, err, "error getting installedCRDs")
209211
apiVersion, err := getGatewayInferenceExtentionVersion(installedCRDs.Items)
210212
if err != nil {
@@ -214,7 +216,7 @@ func RunConformanceWithOptions(t *testing.T, opts confsuite.ConformanceOptions)
214216
require.NoError(t, err, "error getting the gateway ineference extension version")
215217
}
216218
}
217-
SetupConformanceTestSuite(t, cSuite, opts, tests.ConformanceTests)
219+
SetupConformanceTestSuite(ctx, t, cSuite, opts, tests.ConformanceTests)
218220
t.Log("Running Inference Extension conformance tests against all registered tests")
219221
err = cSuite.Run(t, tests.ConformanceTests)
220222
require.NoError(t, err, "error running conformance tests")
@@ -232,7 +234,7 @@ func RunConformanceWithOptions(t *testing.T, opts confsuite.ConformanceOptions)
232234
}
233235
}
234236

235-
func SetupConformanceTestSuite(t *testing.T, suite *confsuite.ConformanceTestSuite, opts confsuite.ConformanceOptions, tests []confsuite.ConformanceTest) {
237+
func SetupConformanceTestSuite(ctx context.Context, t *testing.T, suite *confsuite.ConformanceTestSuite, opts confsuite.ConformanceOptions, tests []confsuite.ConformanceTest) {
236238
suite.Applier.ManifestFS = suite.ManifestFS
237239
if suite.RunTest != "" {
238240
idx := slices.IndexFunc(tests, func(t confsuite.ConformanceTest) bool {
@@ -260,8 +262,8 @@ func SetupConformanceTestSuite(t *testing.T, suite *confsuite.ConformanceTestSui
260262
}
261263
apikubernetes.NamespacesMustBeReady(t, suite.Client, suite.TimeoutConfig, namespaces)
262264

263-
ensureGatewayAvailableAndReady(t, suite.Client, opts, resources.PrimaryGatewayNN)
264-
ensureGatewayAvailableAndReady(t, suite.Client, opts, resources.SecondaryGatewayNN)
265+
ensureGatewayAvailableAndReady(ctx, t, suite.Client, opts, resources.PrimaryGatewayNN)
266+
ensureGatewayAvailableAndReady(ctx, t, suite.Client, opts, resources.SecondaryGatewayNN)
265267
}
266268

267269
func getGatewayInferenceExtentionVersion(crds []apiextensionsv1.CustomResourceDefinition) (string, error) {
@@ -284,7 +286,7 @@ func getGatewayInferenceExtentionVersion(crds []apiextensionsv1.CustomResourceDe
284286

285287
// ensureGatewayAvailableAndReady polls for the specified Gateway to exist and become ready
286288
// with an address and programmed condition.
287-
func ensureGatewayAvailableAndReady(t *testing.T, k8sClient client.Client, opts confsuite.ConformanceOptions, gatewayNN types.NamespacedName) {
289+
func ensureGatewayAvailableAndReady(ctx context.Context, t *testing.T, k8sClient client.Client, opts confsuite.ConformanceOptions, gatewayNN types.NamespacedName) {
288290
t.Helper()
289291

290292
t.Logf("Attempting to fetch Gateway %s/%s.", gatewayNN.Namespace, gatewayNN.Name)
@@ -298,7 +300,6 @@ func ensureGatewayAvailableAndReady(t *testing.T, k8sClient client.Client, opts
298300

299301
logDebugf(t, opts.Debug, "Waiting up to %v for Gateway object %s/%s to appear after manifest application...", waitForGatewayCreationTimeout, gatewayNN.Namespace, gatewayNN.Name)
300302

301-
ctx := context.TODO()
302303
pollErr := wait.PollUntilContextTimeout(ctx, extTimeoutConf.GatewayObjectPollInterval, waitForGatewayCreationTimeout, true, func(pollCtx context.Context) (bool, error) {
303304
fetchErr := k8sClient.Get(pollCtx, gatewayNN, gw)
304305
if fetchErr == nil {

0 commit comments

Comments
 (0)