mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-05 08:02:13 +00:00
lib/watchaggregator: Don't care about timings during testing on darwin
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4502
This commit is contained in:
parent
386cb274bd
commit
ec4c3bae0d
@ -110,7 +110,7 @@ type aggregator struct {
|
|||||||
ctx context.Context
|
ctx context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func new(folderCfg config.FolderConfiguration, ctx context.Context) *aggregator {
|
func newAggregator(folderCfg config.FolderConfiguration, ctx context.Context) *aggregator {
|
||||||
a := &aggregator{
|
a := &aggregator{
|
||||||
folderCfgUpdate: make(chan config.FolderConfiguration),
|
folderCfgUpdate: make(chan config.FolderConfiguration),
|
||||||
notifyTimerNeedsReset: false,
|
notifyTimerNeedsReset: false,
|
||||||
@ -124,7 +124,7 @@ func new(folderCfg config.FolderConfiguration, ctx context.Context) *aggregator
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Aggregate(in <-chan fs.Event, out chan<- []string, folderCfg config.FolderConfiguration, cfg *config.Wrapper, ctx context.Context) {
|
func Aggregate(in <-chan fs.Event, out chan<- []string, folderCfg config.FolderConfiguration, cfg *config.Wrapper, ctx context.Context) {
|
||||||
a := new(folderCfg, ctx)
|
a := newAggregator(folderCfg, ctx)
|
||||||
|
|
||||||
// Necessary for unit tests where the backend is mocked
|
// Necessary for unit tests where the backend is mocked
|
||||||
go a.mainLoop(in, out, cfg)
|
go a.mainLoop(in, out, cfg)
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -62,7 +63,7 @@ func TestAggregate(t *testing.T) {
|
|||||||
folderCfg := defaultFolderCfg.Copy()
|
folderCfg := defaultFolderCfg.Copy()
|
||||||
folderCfg.ID = "Aggregate"
|
folderCfg.ID = "Aggregate"
|
||||||
ctx, _ := context.WithCancel(context.Background())
|
ctx, _ := context.WithCancel(context.Background())
|
||||||
a := new(folderCfg, ctx)
|
a := newAggregator(folderCfg, ctx)
|
||||||
|
|
||||||
// checks whether maxFilesPerDir events in one dir are kept as is
|
// checks whether maxFilesPerDir events in one dir are kept as is
|
||||||
for i := 0; i < maxFilesPerDir; i++ {
|
for i := 0; i < maxFilesPerDir; i++ {
|
||||||
@ -228,54 +229,56 @@ func testScenario(t *testing.T, name string, testCase func(c chan<- fs.Event), e
|
|||||||
|
|
||||||
folderCfg := defaultFolderCfg.Copy()
|
folderCfg := defaultFolderCfg.Copy()
|
||||||
folderCfg.ID = name
|
folderCfg.ID = name
|
||||||
a := new(folderCfg, ctx)
|
a := newAggregator(folderCfg, ctx)
|
||||||
a.notifyTimeout = testNotifyTimeout
|
a.notifyTimeout = testNotifyTimeout
|
||||||
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
go a.mainLoop(eventChan, watchChan, defaultCfg)
|
go a.mainLoop(eventChan, watchChan, defaultCfg)
|
||||||
|
|
||||||
sleepMs(10)
|
sleepMs(20)
|
||||||
go testAggregatorOutput(t, watchChan, expectedBatches, startTime, ctx)
|
|
||||||
|
|
||||||
testCase(eventChan)
|
go testCase(eventChan)
|
||||||
|
|
||||||
|
testAggregatorOutput(t, watchChan, expectedBatches, startTime)
|
||||||
|
|
||||||
timeout := time.NewTimer(time.Duration(expectedBatches[len(expectedBatches)-1].beforeMs+100) * time.Millisecond)
|
|
||||||
<-timeout.C
|
|
||||||
cancel()
|
cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAggregatorOutput(t *testing.T, fsWatchChan <-chan []string, expectedBatches []expectedBatch, startTime time.Time, ctx context.Context) {
|
func testAggregatorOutput(t *testing.T, fsWatchChan <-chan []string, expectedBatches []expectedBatch, startTime time.Time) {
|
||||||
var received []string
|
var received []string
|
||||||
var elapsedTime time.Duration
|
var elapsedTime time.Duration
|
||||||
batchIndex := 0
|
batchIndex := 0
|
||||||
|
timeout := time.NewTimer(10 * time.Second)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-timeout.C:
|
||||||
if batchIndex != len(expectedBatches) {
|
t.Errorf("Timeout: Received only %d batches (%d expected)", batchIndex, len(expectedBatches))
|
||||||
t.Errorf("Received only %d batches (%d expected)", batchIndex, len(expectedBatches))
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
case received = <-fsWatchChan:
|
case received = <-fsWatchChan:
|
||||||
}
|
}
|
||||||
|
|
||||||
if batchIndex >= len(expectedBatches) {
|
|
||||||
t.Errorf("Received batch %d (only %d expected)", batchIndex+1, len(expectedBatches))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
elapsedTime = time.Since(startTime)
|
elapsedTime = time.Since(startTime)
|
||||||
expected := expectedBatches[batchIndex]
|
expected := expectedBatches[batchIndex]
|
||||||
|
|
||||||
|
if runtime.GOOS != "darwin" {
|
||||||
switch {
|
switch {
|
||||||
case elapsedTime < durationMs(expected.afterMs):
|
case elapsedTime < durationMs(expected.afterMs):
|
||||||
t.Errorf("Received batch %d after %v (too soon)", batchIndex+1, elapsedTime)
|
t.Errorf("Received batch %d after %v (too soon)", batchIndex+1, elapsedTime)
|
||||||
|
|
||||||
case elapsedTime > durationMs(expected.beforeMs):
|
case elapsedTime > durationMs(expected.beforeMs):
|
||||||
t.Errorf("Received batch %d after %v (too late)", batchIndex+1, elapsedTime)
|
t.Errorf("Received batch %d after %v (too late)", batchIndex+1, elapsedTime)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case len(received) != len(expected.paths):
|
if len(received) != len(expected.paths) {
|
||||||
t.Errorf("Received %v events instead of %v for batch %v", len(received), len(expected.paths), batchIndex+1)
|
t.Errorf("Received %v events instead of %v for batch %v", len(received), len(expected.paths), batchIndex+1)
|
||||||
}
|
}
|
||||||
compareBatchToExpected(t, received, expected.paths)
|
compareBatchToExpected(t, received, expected.paths)
|
||||||
|
|
||||||
batchIndex++
|
batchIndex++
|
||||||
|
if batchIndex == len(expectedBatches) {
|
||||||
|
// received everything we expected to
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user