From 2f49a5f8c8034748188b837d3d82fef09411d030 Mon Sep 17 00:00:00 2001 From: Scout Wang Date: Wed, 15 Jan 2025 14:46:34 +0800 Subject: [PATCH] test(streamx): fix streamx Recv timeout unit test (#1676) --- pkg/streamx/streamx_user_test.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/streamx/streamx_user_test.go b/pkg/streamx/streamx_user_test.go index 8f316e4104..676c6dfc16 100644 --- a/pkg/streamx/streamx_user_test.go +++ b/pkg/streamx/streamx_user_test.go @@ -619,18 +619,20 @@ func TestStreamingException(t *testing.T) { } }), ) - octx := context.Background() // assert circuitBreaker error + octx := context.Background() atomic.StoreInt32(&circuitBreaker, 1) _, _, err = cli.BidiStream(octx) test.Assert(t, errors.Is(err, circuitBreakerErr), err) atomic.StoreInt32(&circuitBreaker, 0) // assert context deadline error - ctx, cancel := context.WithTimeout(octx, time.Millisecond) - ctx, bs, err := cli.BidiStream(ctx) + octx = context.Background() + ctx, bs, err := cli.BidiStream(octx) test.Assert(t, err == nil, err) + // ctx timeout should be injected before invoking Recv and after creating stream + ctx, cancel := context.WithTimeout(ctx, time.Millisecond) res, err := bs.Recv(ctx) cancel() test.Assert(t, res == nil && err != nil, res, err)