Skip to content

Commit

Permalink
t.Fatalf must be called in the same goroutine as the test
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbourgon committed Apr 4, 2019
1 parent 3a5a1ab commit 2a732c5
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions ulid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,26 +593,30 @@ func TestMonotonicSafe(t *testing.T) {
t0 = ulid.Timestamp(time.Now())
)

var wg sync.WaitGroup
for i := 0; i < 100; i++ {
wg.Add(1)
errs := make(chan error, 100)
for i := 0; i < cap(errs); i++ {
go func() {
defer wg.Done()
u0 := ulid.MustNew(t0, safe)
u1 := ulid.MustNew(t0, safe)
for j := 0; j < 100; j++ {
for j := 0; j < 1024; j++ {
u0, u1 = u1, ulid.MustNew(t0, safe)
if u0.String() >= u1.String() {
t.Fatalf(
errs <- fmt.Errorf(
"%s (%d %x) >= %s (%d %x)",
u0.String(), u0.Time(), u0.Entropy(),
u1.String(), u1.Time(), u1.Entropy(),
)
return
}
}
errs <- nil
}()
}
wg.Wait()
for i := 0; i < cap(errs); i++ {
if err := <-errs; err != nil {
t.Fatal(err)
}
}
}

type safeMonotonicReader struct {
Expand Down

0 comments on commit 2a732c5

Please sign in to comment.