mirror of
https://github.com/elyby/chrly.git
synced 2025-05-31 14:11:51 +05:30
Fix FullBus test
This commit is contained in:
@@ -2,6 +2,7 @@ package mojangtextures
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -328,7 +329,6 @@ func TestPeriodicStrategy(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func TestFullBusStrategy(t *testing.T) {
|
func TestFullBusStrategy(t *testing.T) {
|
||||||
t.Run("should provide iteration immediately when the batch size exceeded", func(t *testing.T) {
|
t.Run("should provide iteration immediately when the batch size exceeded", func(t *testing.T) {
|
||||||
jobs := make([]*job, 10)
|
jobs := make([]*job, 10)
|
||||||
@@ -373,18 +373,19 @@ func TestFullBusStrategy(t *testing.T) {
|
|||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
ch := strategy.GetJobs(ctx)
|
ch := strategy.GetJobs(ctx)
|
||||||
|
|
||||||
|
var startedAt time.Time
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
defer close(done)
|
defer close(done)
|
||||||
startedAt := time.Now()
|
|
||||||
iteration := <-ch
|
iteration := <-ch
|
||||||
duration := time.Now().Sub(startedAt)
|
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.True(t, duration < d*2)
|
||||||
require.Equal(t, jobs, iteration.Jobs)
|
require.Equal(t, jobs, iteration.Jobs)
|
||||||
require.Equal(t, 0, iteration.Queue)
|
require.Equal(t, 0, iteration.Queue)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
startedAt = time.Now()
|
||||||
for _, j := range jobs {
|
for _, j := range jobs {
|
||||||
strategy.Queue(j)
|
strategy.Queue(j)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user