From 832789be038ffd3bbd1d9ba6e2d8a7e30deeb34b Mon Sep 17 00:00:00 2001 From: "user.name: \"Omer Hasson" Date: Fri, 28 Jun 2024 00:09:55 +0300 Subject: [PATCH] move context creation to improve test readability --- internal/xds/rbac/rbac_engine_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/xds/rbac/rbac_engine_test.go b/internal/xds/rbac/rbac_engine_test.go index 0ea428bd0503..a7eefedfc307 100644 --- a/internal/xds/rbac/rbac_engine_test.go +++ b/internal/xds/rbac/rbac_engine_test.go @@ -1747,12 +1747,13 @@ func (s) TestChainEngine(t *testing.T) { // if the chain of RBAC Engines configured as such works as intended. for _, data := range test.rbacQueries { func() { + ctxWithTimeout, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) + defer cancel() // Construct the context with three data points that have enough // information to represent incoming RPC's. This will be how a // user uses this API. A user will have to put MD, PeerInfo, and // the connection the RPC is sent on in the context. - ctx, cancel := context.WithTimeout(metadata.NewIncomingContext(context.Background(), data.rpcData.md), defaultTestTimeout) - defer cancel() + ctx := metadata.NewIncomingContext(ctxWithTimeout, data.rpcData.md) // Make a TCP connection with a certain destination port. The // address/port of this connection will be used to populate the // destination ip/port in RPCData struct. This represents what