|
4 | 4 | "context" |
5 | 5 | "errors" |
6 | 6 | "io" |
7 | | - "sync" |
8 | 7 | "testing" |
9 | | - "time" |
10 | 8 |
|
11 | 9 | "github.com/grpc-ecosystem/go-grpc-middleware/v2/testing/testpb" |
12 | 10 | "github.com/stretchr/testify/require" |
@@ -338,50 +336,3 @@ func (s *requestIDCustomGeneratorTestSuite) TestCustomGenerator() { |
338 | 336 | require.NotEmpty(s.T(), requestIDs) |
339 | 337 | require.Contains(s.T(), requestIDs[0], s.customIDPrefix, "Custom generator should be used") |
340 | 338 | } |
341 | | - |
342 | | -// Test suite for timeout handling |
343 | | -type requestIDTimeoutTestSuite struct { |
344 | | - *testpb.InterceptorTestSuite |
345 | | -} |
346 | | - |
347 | | -func TestRequestIDMiddlewareTimeout(t *testing.T) { |
348 | | - s := &requestIDTimeoutTestSuite{ |
349 | | - InterceptorTestSuite: &testpb.InterceptorTestSuite{ |
350 | | - TestService: &testServer{}, |
351 | | - ServerOpts: []grpc.ServerOption{ |
352 | | - grpc.ChainUnaryInterceptor( |
353 | | - UnaryServerInterceptor(GenerateIfMissing(true)), |
354 | | - ), |
355 | | - }, |
356 | | - ClientOpts: []grpc.DialOption{}, |
357 | | - }, |
358 | | - } |
359 | | - suite.Run(t, s) |
360 | | -} |
361 | | - |
362 | | -// If a stream receives a context that is already cancelled, |
363 | | -// the middleware will not be invoked at all. Therefore, we try to induce |
364 | | -// what happens when the context errors *while the middleware is running*. |
365 | | -// However, right now, this test is only useful when ran by hand and inspecting logs manually, |
366 | | -// because we don't have a way of asserting what logs were emmitted by the middleware. |
367 | | -func (s *requestIDTimeoutTestSuite) TestContextTimeout() { |
368 | | - var wg sync.WaitGroup |
369 | | - for i := 0; i < 10_000; i++ { |
370 | | - wg.Add(1) |
371 | | - wg.Go(func() { |
372 | | - defer wg.Done() |
373 | | - |
374 | | - // context will be cancelled in the middle of the middleware (if we are lucky) |
375 | | - ctx, cancel := context.WithTimeout(s.T().Context(), 1*time.Millisecond) |
376 | | - defer cancel() |
377 | | - |
378 | | - var trailer metadata.MD |
379 | | - _, err := s.Client.PingEmpty(ctx, &testpb.PingEmptyRequest{}, grpc.Trailer(&trailer)) |
380 | | - |
381 | | - // The RPC should fail due to context cancellation, but middleware should handle it gracefully |
382 | | - require.Error(s.T(), err) |
383 | | - }) |
384 | | - } |
385 | | - |
386 | | - wg.Wait() |
387 | | -} |
0 commit comments