mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-02 03:48:26 +00:00
lib/fs: Further unflake watch tests (#4735)
This commit is contained in:
parent
2fdf9bc55d
commit
98f2875b22
@ -67,8 +67,11 @@ func TestWatchIgnore(t *testing.T) {
|
||||
expectedEvents := []Event{
|
||||
{file, NonRemove},
|
||||
}
|
||||
allowedEvents := []Event{
|
||||
{name, NonRemove},
|
||||
}
|
||||
|
||||
testScenario(t, name, testCase, expectedEvents, false, ignored)
|
||||
testScenario(t, name, testCase, expectedEvents, allowedEvents, ignored)
|
||||
}
|
||||
|
||||
func TestWatchRename(t *testing.T) {
|
||||
@ -91,10 +94,13 @@ func TestWatchRename(t *testing.T) {
|
||||
{old, Remove},
|
||||
destEvent,
|
||||
}
|
||||
allowedEvents := []Event{
|
||||
{name, NonRemove},
|
||||
}
|
||||
|
||||
// set the "allow others" flag because we might get the create of
|
||||
// "oldfile" initially
|
||||
testScenario(t, name, testCase, expectedEvents, true, "")
|
||||
testScenario(t, name, testCase, expectedEvents, allowedEvents, "")
|
||||
}
|
||||
|
||||
// TestWatchOutside checks that no changes from outside the folder make it in
|
||||
@ -152,17 +158,23 @@ func TestWatchSubpath(t *testing.T) {
|
||||
func TestWatchOverflow(t *testing.T) {
|
||||
name := "overflow"
|
||||
|
||||
testCase := func() {
|
||||
for i := 0; i < 5*backendBuffer; i++ {
|
||||
createTestFile(name, "file"+strconv.Itoa(i))
|
||||
}
|
||||
}
|
||||
|
||||
expectedEvents := []Event{
|
||||
{".", NonRemove},
|
||||
}
|
||||
|
||||
testScenario(t, name, testCase, expectedEvents, true, "")
|
||||
allowedEvents := []Event{
|
||||
{name, NonRemove},
|
||||
}
|
||||
|
||||
testCase := func() {
|
||||
for i := 0; i < 5*backendBuffer; i++ {
|
||||
file := "file" + strconv.Itoa(i)
|
||||
createTestFile(name, file)
|
||||
allowedEvents = append(allowedEvents, Event{file, NonRemove})
|
||||
}
|
||||
}
|
||||
|
||||
testScenario(t, name, testCase, expectedEvents, allowedEvents, "")
|
||||
}
|
||||
|
||||
// path relative to folder root, also creates parent dirs if necessary
|
||||
@ -191,7 +203,7 @@ func sleepMs(ms int) {
|
||||
time.Sleep(time.Duration(ms) * time.Millisecond)
|
||||
}
|
||||
|
||||
func testScenario(t *testing.T, name string, testCase func(), expectedEvents []Event, allowOthers bool, ignored string) {
|
||||
func testScenario(t *testing.T, name string, testCase func(), expectedEvents, allowedEvents []Event, ignored string) {
|
||||
if err := testFs.MkdirAll(name, 0755); err != nil {
|
||||
panic(fmt.Sprintf("Failed to create directory %s: %s", name, err))
|
||||
}
|
||||
@ -209,7 +221,7 @@ func testScenario(t *testing.T, name string, testCase func(), expectedEvents []E
|
||||
panic(err)
|
||||
}
|
||||
|
||||
go testWatchOutput(t, name, eventChan, expectedEvents, allowOthers, ctx, cancel)
|
||||
go testWatchOutput(t, name, eventChan, expectedEvents, allowedEvents, ctx, cancel)
|
||||
|
||||
testCase()
|
||||
|
||||
@ -221,7 +233,7 @@ func testScenario(t *testing.T, name string, testCase func(), expectedEvents []E
|
||||
}
|
||||
}
|
||||
|
||||
func testWatchOutput(t *testing.T, name string, in <-chan Event, expectedEvents []Event, allowOthers bool, ctx context.Context, cancel context.CancelFunc) {
|
||||
func testWatchOutput(t *testing.T, name string, in <-chan Event, expectedEvents, allowedEvents []Event, ctx context.Context, cancel context.CancelFunc) {
|
||||
var expected = make(map[Event]struct{})
|
||||
for _, ev := range expectedEvents {
|
||||
ev.Name = filepath.Join(name, ev.Name)
|
||||
@ -248,7 +260,7 @@ func testWatchOutput(t *testing.T, name string, in <-chan Event, expectedEvents
|
||||
}
|
||||
|
||||
if _, ok := expected[received]; !ok {
|
||||
if allowOthers {
|
||||
if len(allowedEvents) > 0 {
|
||||
sleepMs(100) // To facilitate overflow
|
||||
continue
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user