2017-10-20 14:52:55 +00:00
|
|
|
// Copyright (C) 2016 The Syncthing Authors.
|
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
// You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
package watchaggregator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2022-07-28 17:36:39 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/build"
|
2017-10-20 14:52:55 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/config"
|
|
|
|
"github.com/syncthing/syncthing/lib/events"
|
|
|
|
"github.com/syncthing/syncthing/lib/fs"
|
2020-11-20 13:21:54 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/protocol"
|
2017-10-20 14:52:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
maxFiles = 32
|
|
|
|
maxFilesPerDir = 8
|
|
|
|
|
2018-05-26 09:08:23 +00:00
|
|
|
ret := m.Run()
|
|
|
|
|
|
|
|
maxFiles = 512
|
|
|
|
maxFilesPerDir = 128
|
|
|
|
|
|
|
|
os.Exit(ret)
|
2017-10-20 14:52:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
2018-05-26 09:08:23 +00:00
|
|
|
testNotifyDelayS = 1
|
|
|
|
testNotifyTimeout = 2 * time.Second
|
|
|
|
timeoutWithinBatch = time.Second
|
2017-10-20 14:52:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
folderRoot = filepath.Clean("/home/someuser/syncthing")
|
|
|
|
defaultFolderCfg = config.FolderConfiguration{
|
refactor: use modern Protobuf encoder (#9817)
At a high level, this is what I've done and why:
- I'm moving the protobuf generation for the `protocol`, `discovery` and
`db` packages to the modern alternatives, and using `buf` to generate
because it's nice and simple.
- After trying various approaches on how to integrate the new types with
the existing code, I opted for splitting off our own data model types
from the on-the-wire generated types. This means we can have a
`FileInfo` type with nicer ergonomics and lots of methods, while the
protobuf generated type stays clean and close to the wire protocol. It
does mean copying between the two when required, which certainly adds a
small amount of inefficiency. If we want to walk this back in the future
and use the raw generated type throughout, that's possible, this however
makes the refactor smaller (!) as it doesn't change everything about the
type for everyone at the same time.
- I have simply removed in cold blood a significant number of old
database migrations. These depended on previous generations of generated
messages of various kinds and were annoying to support in the new
fashion. The oldest supported database version now is the one from
Syncthing 1.9.0 from Sep 7, 2020.
- I changed config structs to be regular manually defined structs.
For the sake of discussion, some things I tried that turned out not to
work...
### Embedding / wrapping
Embedding the protobuf generated structs in our existing types as a data
container and keeping our methods and stuff:
```
package protocol
type FileInfo struct {
*generated.FileInfo
}
```
This generates a lot of problems because the internal shape of the
generated struct is quite different (different names, different types,
more pointers), because initializing it doesn't work like you'd expect
(i.e., you end up with an embedded nil pointer and a panic), and because
the types of child types don't get wrapped. That is, even if we also
have a similar wrapper around a `Vector`, that's not the type you get
when accessing `someFileInfo.Version`, you get the `*generated.Vector`
that doesn't have methods, etc.
### Aliasing
```
package protocol
type FileInfo = generated.FileInfo
```
Doesn't help because you can't attach methods to it, plus all the above.
### Generating the types into the target package like we do now and
attaching methods
This fails because of the different shape of the generated type (as in
the embedding case above) plus the generated struct already has a bunch
of methods that we can't necessarily override properly (like `String()`
and a bunch of getters).
### Methods to functions
I considered just moving all the methods we attach to functions in a
specific package, so that for example
```
package protocol
func (f FileInfo) Equal(other FileInfo) bool
```
would become
```
package fileinfos
func Equal(a, b *generated.FileInfo) bool
```
and this would mostly work, but becomes quite verbose and cumbersome,
and somewhat limits discoverability (you can't see what methods are
available on the type in auto completions, etc). In the end I did this
in some cases, like in the database layer where a lot of things like
`func (fv *FileVersion) IsEmpty() bool` becomes `func fvIsEmpty(fv
*generated.FileVersion)` because they were anyway just internal methods.
Fixes #8247
2024-12-01 15:50:17 +00:00
|
|
|
FilesystemType: config.FilesystemTypeBasic,
|
2017-10-20 14:52:55 +00:00
|
|
|
Path: folderRoot,
|
|
|
|
FSWatcherDelayS: testNotifyDelayS,
|
|
|
|
}
|
|
|
|
defaultCfg = config.Wrap("", config.Configuration{
|
|
|
|
Folders: []config.FolderConfiguration{defaultFolderCfg},
|
2020-11-20 13:21:54 +00:00
|
|
|
}, protocol.LocalDeviceID, events.NoopLogger)
|
2017-10-20 14:52:55 +00:00
|
|
|
)
|
|
|
|
|
2018-05-26 09:08:23 +00:00
|
|
|
// Represents possibly multiple (different event types) expected paths from
|
|
|
|
// aggregation, that should be received back to back.
|
2017-10-20 14:52:55 +00:00
|
|
|
type expectedBatch struct {
|
2018-05-26 09:08:23 +00:00
|
|
|
paths [][]string
|
2017-10-20 14:52:55 +00:00
|
|
|
afterMs int
|
|
|
|
beforeMs int
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestAggregate checks whether maxFilesPerDir+1 events in one dir are
|
|
|
|
// aggregated to parent dir
|
|
|
|
func TestAggregate(t *testing.T) {
|
|
|
|
inProgress := make(map[string]struct{})
|
|
|
|
|
|
|
|
folderCfg := defaultFolderCfg.Copy()
|
|
|
|
folderCfg.ID = "Aggregate"
|
2019-02-02 10:45:17 +00:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
2019-11-21 07:41:15 +00:00
|
|
|
a := newAggregator(ctx, folderCfg)
|
2017-10-20 14:52:55 +00:00
|
|
|
|
|
|
|
// checks whether maxFilesPerDir events in one dir are kept as is
|
|
|
|
for i := 0; i < maxFilesPerDir; i++ {
|
2019-02-02 10:45:17 +00:00
|
|
|
a.newEvent(fs.Event{
|
|
|
|
Name: filepath.Join("parent", strconv.Itoa(i)),
|
|
|
|
Type: fs.NonRemove,
|
|
|
|
}, inProgress)
|
2017-10-20 14:52:55 +00:00
|
|
|
}
|
2018-05-26 09:08:23 +00:00
|
|
|
if l := len(getEventPaths(a.root, ".", a)); l != maxFilesPerDir {
|
|
|
|
t.Errorf("Unexpected number of events stored, got %v, expected %v", l, maxFilesPerDir)
|
2017-10-20 14:52:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// checks whether maxFilesPerDir+1 events in one dir are aggregated to parent dir
|
2019-02-02 10:45:17 +00:00
|
|
|
a.newEvent(fs.Event{
|
|
|
|
Name: filepath.Join("parent", "new"),
|
|
|
|
Type: fs.NonRemove,
|
|
|
|
}, inProgress)
|
2018-05-26 09:08:23 +00:00
|
|
|
compareBatchToExpectedDirect(t, getEventPaths(a.root, ".", a), []string{"parent"})
|
2017-10-20 14:52:55 +00:00
|
|
|
|
|
|
|
// checks that adding an event below "parent" does not change anything
|
2019-02-02 10:45:17 +00:00
|
|
|
a.newEvent(fs.Event{
|
|
|
|
Name: filepath.Join("parent", "extra"),
|
|
|
|
Type: fs.NonRemove,
|
|
|
|
}, inProgress)
|
2018-05-26 09:08:23 +00:00
|
|
|
compareBatchToExpectedDirect(t, getEventPaths(a.root, ".", a), []string{"parent"})
|
2017-10-20 14:52:55 +00:00
|
|
|
|
|
|
|
// again test aggregation in "parent" but with event in subdirs
|
2019-11-21 07:41:15 +00:00
|
|
|
a = newAggregator(ctx, folderCfg)
|
2017-10-20 14:52:55 +00:00
|
|
|
for i := 0; i < maxFilesPerDir; i++ {
|
2019-02-02 10:45:17 +00:00
|
|
|
a.newEvent(fs.Event{
|
|
|
|
Name: filepath.Join("parent", strconv.Itoa(i)),
|
|
|
|
Type: fs.NonRemove,
|
|
|
|
}, inProgress)
|
2017-10-20 14:52:55 +00:00
|
|
|
}
|
2019-02-02 10:45:17 +00:00
|
|
|
a.newEvent(fs.Event{
|
|
|
|
Name: filepath.Join("parent", "sub", "new"),
|
|
|
|
Type: fs.NonRemove,
|
|
|
|
}, inProgress)
|
2018-05-26 09:08:23 +00:00
|
|
|
compareBatchToExpectedDirect(t, getEventPaths(a.root, ".", a), []string{"parent"})
|
2017-10-20 14:52:55 +00:00
|
|
|
|
|
|
|
// test aggregation in root
|
2019-11-21 07:41:15 +00:00
|
|
|
a = newAggregator(ctx, folderCfg)
|
2017-10-20 14:52:55 +00:00
|
|
|
for i := 0; i < maxFiles; i++ {
|
2019-02-02 10:45:17 +00:00
|
|
|
a.newEvent(fs.Event{
|
|
|
|
Name: strconv.Itoa(i),
|
|
|
|
Type: fs.NonRemove,
|
|
|
|
}, inProgress)
|
2017-10-20 14:52:55 +00:00
|
|
|
}
|
2018-05-26 09:08:23 +00:00
|
|
|
if len(getEventPaths(a.root, ".", a)) != maxFiles {
|
2017-10-20 14:52:55 +00:00
|
|
|
t.Errorf("Unexpected number of events stored in root")
|
|
|
|
}
|
2019-02-02 10:45:17 +00:00
|
|
|
a.newEvent(fs.Event{
|
|
|
|
Name: filepath.Join("parent", "sub", "new"),
|
|
|
|
Type: fs.NonRemove,
|
|
|
|
}, inProgress)
|
2018-05-26 09:08:23 +00:00
|
|
|
compareBatchToExpectedDirect(t, getEventPaths(a.root, ".", a), []string{"."})
|
2017-10-20 14:52:55 +00:00
|
|
|
|
|
|
|
// checks that adding an event when "." is already stored is a noop
|
2019-02-02 10:45:17 +00:00
|
|
|
a.newEvent(fs.Event{
|
|
|
|
Name: "anythingelse",
|
|
|
|
Type: fs.NonRemove,
|
|
|
|
}, inProgress)
|
2018-05-26 09:08:23 +00:00
|
|
|
compareBatchToExpectedDirect(t, getEventPaths(a.root, ".", a), []string{"."})
|
2017-10-20 14:52:55 +00:00
|
|
|
|
2019-11-21 07:41:15 +00:00
|
|
|
a = newAggregator(ctx, folderCfg)
|
2017-10-20 14:52:55 +00:00
|
|
|
filesPerDir := maxFilesPerDir / 2
|
|
|
|
dirs := make([]string, maxFiles/filesPerDir+1)
|
|
|
|
for i := 0; i < maxFiles/filesPerDir+1; i++ {
|
|
|
|
dirs[i] = "dir" + strconv.Itoa(i)
|
|
|
|
}
|
|
|
|
for _, dir := range dirs {
|
|
|
|
for i := 0; i < filesPerDir; i++ {
|
2019-02-02 10:45:17 +00:00
|
|
|
a.newEvent(fs.Event{
|
|
|
|
Name: filepath.Join(dir, strconv.Itoa(i)),
|
|
|
|
Type: fs.NonRemove,
|
|
|
|
}, inProgress)
|
2017-10-20 14:52:55 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-26 09:08:23 +00:00
|
|
|
compareBatchToExpectedDirect(t, getEventPaths(a.root, ".", a), []string{"."})
|
2017-10-20 14:52:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TestInProgress checks that ignoring files currently edited by Syncthing works
|
|
|
|
func TestInProgress(t *testing.T) {
|
2019-08-15 14:29:37 +00:00
|
|
|
evLogger := events.NewLogger()
|
2020-11-17 12:19:04 +00:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
go evLogger.Serve(ctx)
|
|
|
|
defer cancel()
|
2017-10-20 14:52:55 +00:00
|
|
|
testCase := func(c chan<- fs.Event) {
|
2019-08-15 14:29:37 +00:00
|
|
|
evLogger.Log(events.ItemStarted, map[string]string{
|
2017-10-20 14:52:55 +00:00
|
|
|
"item": "inprogress",
|
|
|
|
})
|
|
|
|
sleepMs(100)
|
|
|
|
c <- fs.Event{Name: "inprogress", Type: fs.NonRemove}
|
|
|
|
sleepMs(1000)
|
2019-08-15 14:29:37 +00:00
|
|
|
evLogger.Log(events.ItemFinished, map[string]interface{}{
|
2017-10-20 14:52:55 +00:00
|
|
|
"item": "inprogress",
|
|
|
|
})
|
|
|
|
sleepMs(100)
|
|
|
|
c <- fs.Event{Name: "notinprogress", Type: fs.NonRemove}
|
|
|
|
sleepMs(800)
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedBatches := []expectedBatch{
|
2018-05-26 09:08:23 +00:00
|
|
|
{[][]string{{"notinprogress"}}, 2000, 3500},
|
2017-10-20 14:52:55 +00:00
|
|
|
}
|
|
|
|
|
2019-08-15 14:29:37 +00:00
|
|
|
testScenario(t, "InProgress", testCase, expectedBatches, evLogger)
|
2017-10-20 14:52:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TestDelay checks that recurring changes to the same path are delayed
|
|
|
|
// and different types separated and ordered correctly
|
|
|
|
func TestDelay(t *testing.T) {
|
|
|
|
file := filepath.Join("parent", "file")
|
|
|
|
delayed := "delayed"
|
|
|
|
del := "deleted"
|
2018-05-26 09:08:23 +00:00
|
|
|
delAfter := "deletedAfter"
|
2017-10-20 14:52:55 +00:00
|
|
|
both := filepath.Join("parent", "sub", "both")
|
|
|
|
testCase := func(c chan<- fs.Event) {
|
|
|
|
sleepMs(200)
|
|
|
|
c <- fs.Event{Name: file, Type: fs.NonRemove}
|
|
|
|
delay := time.Duration(300) * time.Millisecond
|
|
|
|
timer := time.NewTimer(delay)
|
|
|
|
<-timer.C
|
|
|
|
timer.Reset(delay)
|
|
|
|
c <- fs.Event{Name: delayed, Type: fs.NonRemove}
|
|
|
|
c <- fs.Event{Name: both, Type: fs.NonRemove}
|
|
|
|
c <- fs.Event{Name: both, Type: fs.Remove}
|
|
|
|
c <- fs.Event{Name: del, Type: fs.Remove}
|
|
|
|
for i := 0; i < 9; i++ {
|
|
|
|
<-timer.C
|
|
|
|
timer.Reset(delay)
|
|
|
|
c <- fs.Event{Name: delayed, Type: fs.NonRemove}
|
|
|
|
}
|
2018-05-26 09:08:23 +00:00
|
|
|
c <- fs.Event{Name: delAfter, Type: fs.Remove}
|
2017-10-20 14:52:55 +00:00
|
|
|
<-timer.C
|
|
|
|
}
|
|
|
|
|
|
|
|
// batches that we expect to receive with time interval in milliseconds
|
|
|
|
expectedBatches := []expectedBatch{
|
2018-05-26 09:08:23 +00:00
|
|
|
{[][]string{{file}}, 500, 2500},
|
|
|
|
{[][]string{{delayed}, {both}, {del}}, 2500, 4500},
|
|
|
|
{[][]string{{delayed}, {delAfter}}, 3600, 7000},
|
2017-10-20 14:52:55 +00:00
|
|
|
}
|
|
|
|
|
2019-08-15 14:29:37 +00:00
|
|
|
testScenario(t, "Delay", testCase, expectedBatches, nil)
|
2017-10-20 14:52:55 +00:00
|
|
|
}
|
|
|
|
|
2018-08-13 07:14:03 +00:00
|
|
|
// TestNoDelay checks that no delay occurs if there are no non-remove events
|
|
|
|
func TestNoDelay(t *testing.T) {
|
|
|
|
mixed := "foo"
|
|
|
|
del := "bar"
|
|
|
|
testCase := func(c chan<- fs.Event) {
|
|
|
|
c <- fs.Event{Name: mixed, Type: fs.NonRemove}
|
|
|
|
c <- fs.Event{Name: mixed, Type: fs.Remove}
|
|
|
|
c <- fs.Event{Name: del, Type: fs.Remove}
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedBatches := []expectedBatch{
|
|
|
|
{[][]string{{mixed}, {del}}, 500, 2000},
|
|
|
|
}
|
|
|
|
|
2019-08-15 14:29:37 +00:00
|
|
|
testScenario(t, "NoDelay", testCase, expectedBatches, nil)
|
2018-08-13 07:14:03 +00:00
|
|
|
}
|
|
|
|
|
2017-10-20 14:52:55 +00:00
|
|
|
func getEventPaths(dir *eventDir, dirPath string, a *aggregator) []string {
|
|
|
|
var paths []string
|
|
|
|
for childName, childDir := range dir.dirs {
|
2019-02-02 11:09:07 +00:00
|
|
|
paths = append(paths, getEventPaths(childDir, filepath.Join(dirPath, childName), a)...)
|
2017-10-20 14:52:55 +00:00
|
|
|
}
|
|
|
|
for name := range dir.events {
|
|
|
|
paths = append(paths, filepath.Join(dirPath, name))
|
|
|
|
}
|
|
|
|
return paths
|
|
|
|
}
|
|
|
|
|
|
|
|
func sleepMs(ms int) {
|
|
|
|
time.Sleep(time.Duration(ms) * time.Millisecond)
|
|
|
|
}
|
|
|
|
|
|
|
|
func durationMs(ms int) time.Duration {
|
|
|
|
return time.Duration(ms) * time.Millisecond
|
|
|
|
}
|
|
|
|
|
2018-05-26 09:08:23 +00:00
|
|
|
func compareBatchToExpected(batch []string, expectedPaths []string) (missing []string, unexpected []string) {
|
2017-10-20 14:52:55 +00:00
|
|
|
for _, expected := range expectedPaths {
|
|
|
|
expected = filepath.Clean(expected)
|
|
|
|
found := false
|
|
|
|
for i, received := range batch {
|
|
|
|
if expected == received {
|
|
|
|
found = true
|
|
|
|
batch = append(batch[:i], batch[i+1:]...)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !found {
|
2018-05-26 09:08:23 +00:00
|
|
|
missing = append(missing, expected)
|
2017-10-20 14:52:55 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-02 11:09:07 +00:00
|
|
|
unexpected = append(unexpected, batch...)
|
2018-05-26 09:08:23 +00:00
|
|
|
return missing, unexpected
|
|
|
|
}
|
|
|
|
|
|
|
|
func compareBatchToExpectedDirect(t *testing.T, batch []string, expectedPaths []string) {
|
|
|
|
t.Helper()
|
|
|
|
missing, unexpected := compareBatchToExpected(batch, expectedPaths)
|
|
|
|
for _, p := range missing {
|
|
|
|
t.Errorf("Did not receive event %s", p)
|
|
|
|
}
|
|
|
|
for _, p := range unexpected {
|
|
|
|
t.Errorf("Received unexpected event %s", p)
|
2017-10-20 14:52:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-15 14:29:37 +00:00
|
|
|
func testScenario(t *testing.T, name string, testCase func(c chan<- fs.Event), expectedBatches []expectedBatch, evLogger events.Logger) {
|
2018-05-26 09:08:23 +00:00
|
|
|
t.Helper()
|
2019-08-15 14:29:37 +00:00
|
|
|
|
|
|
|
if evLogger == nil {
|
|
|
|
evLogger = events.NoopLogger
|
|
|
|
}
|
|
|
|
|
2017-10-20 14:52:55 +00:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
eventChan := make(chan fs.Event)
|
|
|
|
watchChan := make(chan []string)
|
|
|
|
|
|
|
|
folderCfg := defaultFolderCfg.Copy()
|
|
|
|
folderCfg.ID = name
|
2019-11-21 07:41:15 +00:00
|
|
|
a := newAggregator(ctx, folderCfg)
|
2017-10-20 14:52:55 +00:00
|
|
|
a.notifyTimeout = testNotifyTimeout
|
|
|
|
|
|
|
|
startTime := time.Now()
|
2019-08-15 14:29:37 +00:00
|
|
|
go a.mainLoop(eventChan, watchChan, defaultCfg, evLogger)
|
2017-10-20 14:52:55 +00:00
|
|
|
|
2017-11-10 17:05:31 +00:00
|
|
|
sleepMs(20)
|
2017-10-20 14:52:55 +00:00
|
|
|
|
2017-11-10 17:05:31 +00:00
|
|
|
go testCase(eventChan)
|
|
|
|
|
|
|
|
testAggregatorOutput(t, watchChan, expectedBatches, startTime)
|
2017-10-20 14:52:55 +00:00
|
|
|
|
|
|
|
cancel()
|
|
|
|
}
|
|
|
|
|
2017-11-10 17:05:31 +00:00
|
|
|
func testAggregatorOutput(t *testing.T, fsWatchChan <-chan []string, expectedBatches []expectedBatch, startTime time.Time) {
|
2018-05-26 09:08:23 +00:00
|
|
|
t.Helper()
|
2017-10-20 14:52:55 +00:00
|
|
|
var received []string
|
|
|
|
var elapsedTime time.Duration
|
2018-05-26 09:08:23 +00:00
|
|
|
var batchIndex, innerIndex int
|
2017-11-10 17:05:31 +00:00
|
|
|
timeout := time.NewTimer(10 * time.Second)
|
2017-10-20 14:52:55 +00:00
|
|
|
for {
|
|
|
|
select {
|
2017-11-10 17:05:31 +00:00
|
|
|
case <-timeout.C:
|
|
|
|
t.Errorf("Timeout: Received only %d batches (%d expected)", batchIndex, len(expectedBatches))
|
2017-10-20 14:52:55 +00:00
|
|
|
return
|
|
|
|
case received = <-fsWatchChan:
|
|
|
|
}
|
|
|
|
|
2018-05-26 09:08:23 +00:00
|
|
|
if batchIndex >= len(expectedBatches) {
|
|
|
|
t.Errorf("Received batch %d, expected only %d", batchIndex+1, len(expectedBatches))
|
|
|
|
continue
|
|
|
|
}
|
2017-10-20 14:52:55 +00:00
|
|
|
|
2022-07-28 17:36:39 +00:00
|
|
|
if !build.IsDarwin {
|
2018-05-26 09:08:23 +00:00
|
|
|
now := time.Since(startTime)
|
|
|
|
if innerIndex == 0 {
|
|
|
|
switch {
|
|
|
|
case now < durationMs(expectedBatches[batchIndex].afterMs):
|
2018-08-13 07:14:03 +00:00
|
|
|
t.Errorf("Received batch %d after %v (too soon)", batchIndex+1, now)
|
2018-05-26 09:08:23 +00:00
|
|
|
|
|
|
|
case now > durationMs(expectedBatches[batchIndex].beforeMs):
|
2018-08-13 07:14:03 +00:00
|
|
|
t.Errorf("Received batch %d after %v (too late)", batchIndex+1, now)
|
2018-05-26 09:08:23 +00:00
|
|
|
}
|
|
|
|
} else if innerTime := now - elapsedTime; innerTime > timeoutWithinBatch {
|
|
|
|
t.Errorf("Receive part %d of batch %d after %v (too late)", innerIndex+1, batchIndex+1, innerTime)
|
2017-11-10 17:05:31 +00:00
|
|
|
}
|
2018-05-26 09:08:23 +00:00
|
|
|
elapsedTime = now
|
2017-11-10 17:05:31 +00:00
|
|
|
}
|
2017-10-20 14:52:55 +00:00
|
|
|
|
2018-05-26 09:08:23 +00:00
|
|
|
expected := expectedBatches[batchIndex].paths[innerIndex]
|
|
|
|
|
|
|
|
if len(received) != len(expected) {
|
|
|
|
t.Errorf("Received %v events instead of %v for batch %v", len(received), len(expected), batchIndex+1)
|
|
|
|
}
|
|
|
|
missing, unexpected := compareBatchToExpected(received, expected)
|
|
|
|
for _, p := range missing {
|
|
|
|
t.Errorf("Did not receive event %s in batch %d (%d)", p, batchIndex+1, innerIndex+1)
|
|
|
|
}
|
|
|
|
for _, p := range unexpected {
|
|
|
|
t.Errorf("Received unexpected event %s in batch %d (%d)", p, batchIndex+1, innerIndex+1)
|
2017-10-20 14:52:55 +00:00
|
|
|
}
|
2017-11-10 17:05:31 +00:00
|
|
|
|
2018-05-26 09:08:23 +00:00
|
|
|
if innerIndex == len(expectedBatches[batchIndex].paths)-1 {
|
|
|
|
if batchIndex == len(expectedBatches)-1 {
|
|
|
|
// received everything we expected to
|
|
|
|
return
|
|
|
|
}
|
|
|
|
innerIndex = 0
|
|
|
|
batchIndex++
|
|
|
|
} else {
|
|
|
|
innerIndex++
|
2017-11-10 17:05:31 +00:00
|
|
|
}
|
2017-10-20 14:52:55 +00:00
|
|
|
}
|
|
|
|
}
|