From d0f7a20a2d6cd334a4f29700fc9db56487a101d8 Mon Sep 17 00:00:00 2001 From: Sergei Razorenov Date: Wed, 1 Nov 2023 00:33:14 +0300 Subject: [PATCH] clarify test --- errsizedgroup_test.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/errsizedgroup_test.go b/errsizedgroup_test.go index 7803a82..fdaccba 100644 --- a/errsizedgroup_test.go +++ b/errsizedgroup_test.go @@ -134,18 +134,17 @@ func TestErrorSizedGroup_TermOnErr(t *testing.T) { for i := 0; i < N; i++ { i := i ewg.Go(func(ctx context.Context) error { - val := atomic.AddUint32(&c, 1) - if i == errIndex || val > uint32(errIndex+1) { + if val := atomic.AddUint32(&c, 1); i == errIndex || val > errIndex+1 { return fmt.Errorf("err from function %d", i) } return nil }) } - err := ewg.Wait() - + err := ewg.Wait() // with some probability it can return "{err from function 101}" + require.Len(t, err.(*MultiError).Errors(), 1) require.NotNil(t, err) - require.Contains(t, err.Error(), "err from function 100") + require.ErrorContains(t, err, "err from function 100") // we don't know how many routines will be executed before the error, but it should be less than 10 require.LessOrEqual(t, c, uint32(errIndex+100), fmt.Sprintf("%d, routines have to be terminated early", c)) }