Skip to content

Commit

Permalink
clarify test
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-87 committed Nov 1, 2023
1 parent bcf5e51 commit d0f7a20
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions errsizedgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down

0 comments on commit d0f7a20

Please sign in to comment.