Fix FullBus test

This commit is contained in:
ErickSkrauch 2020-04-26 20:58:46 +03:00
parent d8f6786c69
commit b2e501af60

View File

@ -2,6 +2,7 @@ package mojangtextures
import (
"context"
"fmt"
"strconv"
"sync"
"testing"
@ -328,7 +329,6 @@ func TestPeriodicStrategy(t *testing.T) {
})
}
func TestFullBusStrategy(t *testing.T) {
t.Run("should provide iteration immediately when the batch size exceeded", func(t *testing.T) {
jobs := make([]*job, 10)
@ -373,18 +373,19 @@ func TestFullBusStrategy(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
ch := strategy.GetJobs(ctx)
var startedAt time.Time
done := make(chan struct{})
go func() {
defer close(done)
startedAt := time.Now()
iteration := <-ch
duration := time.Now().Sub(startedAt)
require.True(t, duration >= d)
require.True(t, duration >= d, fmt.Sprintf("has %d, expected %d", duration, d))
require.True(t, duration < d*2)
require.Equal(t, jobs, iteration.Jobs)
require.Equal(t, 0, iteration.Queue)
}()
startedAt = time.Now()
for _, j := range jobs {
strategy.Queue(j)
}