fileutil: update watcher to use fsnotify and polling (#3663)

* fileutil: update watcher to use fsnotify and polling

* raise timeout

* maybe fix
This commit is contained in:
Caleb Doxsey 2022-10-19 09:13:08 -06:00 committed by GitHub
parent daed2d260c
commit d147846e64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 315 additions and 34 deletions

View file

@ -0,0 +1,25 @@
package chanutil
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestBatch(t *testing.T) {
ch1 := make(chan int)
go func() {
for _, i := range []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} {
ch1 <- i
}
close(ch1)
}()
ch2 := Batch(ch1, WithBatchMaxWait(time.Millisecond*10), WithBatchMaxSize(3))
assert.Equal(t, []int{1, 2, 3}, <-ch2)
assert.Equal(t, []int{4, 5, 6}, <-ch2)
assert.Equal(t, []int{7, 8, 9}, <-ch2)
assert.Equal(t, []int{10}, <-ch2)
assert.Equal(t, []int(nil), <-ch2)
}