Skip to content

Commit

Permalink
add sync runner for test assert access
Browse files Browse the repository at this point in the history
  • Loading branch information
1pkg committed Oct 14, 2020
1 parent 9fad9d4 commit f0d8a90
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions throttlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const (
ms30_0 time.Duration = 30 * time.Millisecond
)

var trun Runner = NewRunnerAsync(context.Background(), NewThrottlerBuffered(0))

type tcase struct {
tms uint64 // number of sub runs inside one case
thr Throttler // throttler itself
Expand Down Expand Up @@ -773,13 +775,16 @@ func TestThrottlers(t *testing.T) {
wg.Add(int(ptrtcase.tms))
for i := 0; i < int(ptrtcase.tms); i++ {
t.Run(fmt.Sprintf("run %d", i+1), func(t *testing.T) {
go func(t *testing.T, index int, tcase *tcase) {
go func(index int, tcase *tcase) {
defer wg.Done()
rdur, rerr := tcase.result(index)
dur, err := tcase.run(index)
assert.Equal(t, rerr, err)
assert.LessOrEqual(t, int64(rdur/2), int64(dur))
}(t, i, &ptrtcase)
trun.Run(func(context.Context) error {
assert.Equal(t, rerr, err)
assert.LessOrEqual(t, int64(rdur/2), int64(dur))
return nil
})
}(i, &ptrtcase)
})
}
wg.Wait()
Expand Down

0 comments on commit f0d8a90

Please sign in to comment.