From d448bd9e2fe158f63cb4cabc249cbf4c5631feee Mon Sep 17 00:00:00 2001 From: Piotr Piotrowski Date: Mon, 5 Dec 2022 10:53:04 +0100 Subject: [PATCH] Increate wait time, fix object store test --- test/basic_test.go | 2 +- test/object_test.go | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/test/basic_test.go b/test/basic_test.go index c337cf679..e9a0fa6d5 100644 --- a/test/basic_test.go +++ b/test/basic_test.go @@ -56,7 +56,7 @@ func getStableNumGoroutine(t *testing.T) int { func checkNoGoroutineLeak(t *testing.T, base int, action string) { t.Helper() - waitFor(t, 5*time.Second, 100*time.Millisecond, func() error { + waitFor(t, 10*time.Second, 100*time.Millisecond, func() error { delta := (runtime.NumGoroutine() - base) if delta > 0 { return fmt.Errorf("%d Go routines still exist after %s", delta, action) diff --git a/test/object_test.go b/test/object_test.go index b9a1b30cf..1cc5e3aa2 100644 --- a/test/object_test.go +++ b/test/object_test.go @@ -827,11 +827,26 @@ func TestObjectList(t *testing.T) { } }) - t.Run("context timeout", func(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), 1*time.Nanosecond) - defer cancel() - _, err := root.List(nats.Context(ctx)) - expectErr(t, err, context.DeadlineExceeded) + t.Run("context canceled", func(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + + errs := make(chan error) + go func() { + for { + _, err := root.List(nats.Context(ctx)) + if err != nil { + errs <- err + } + } + }() + time.Sleep(10 * time.Millisecond) + cancel() + select { + case err := <-errs: + expectErr(t, err, context.Canceled) + case <-time.After(5 * time.Second): + t.Fatal("Expected error, got none") + } }) }