mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-02 11:58:28 +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{
|
expectedEvents := []Event{
|
||||||
{file, NonRemove},
|
{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) {
|
func TestWatchRename(t *testing.T) {
|
||||||
@ -91,10 +94,13 @@ func TestWatchRename(t *testing.T) {
|
|||||||
{old, Remove},
|
{old, Remove},
|
||||||
destEvent,
|
destEvent,
|
||||||
}
|
}
|
||||||
|
allowedEvents := []Event{
|
||||||
|
{name, NonRemove},
|
||||||
|
}
|
||||||
|
|
||||||
// set the "allow others" flag because we might get the create of
|
// set the "allow others" flag because we might get the create of
|
||||||
// "oldfile" initially
|
// "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
|
// 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) {
|
func TestWatchOverflow(t *testing.T) {
|
||||||
name := "overflow"
|
name := "overflow"
|
||||||
|
|
||||||
testCase := func() {
|
|
||||||
for i := 0; i < 5*backendBuffer; i++ {
|
|
||||||
createTestFile(name, "file"+strconv.Itoa(i))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
expectedEvents := []Event{
|
expectedEvents := []Event{
|
||||||
{".", NonRemove},
|
{".", 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
|
// 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)
|
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 {
|
if err := testFs.MkdirAll(name, 0755); err != nil {
|
||||||
panic(fmt.Sprintf("Failed to create directory %s: %s", name, err))
|
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)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
go testWatchOutput(t, name, eventChan, expectedEvents, allowOthers, ctx, cancel)
|
go testWatchOutput(t, name, eventChan, expectedEvents, allowedEvents, ctx, cancel)
|
||||||
|
|
||||||
testCase()
|
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{})
|
var expected = make(map[Event]struct{})
|
||||||
for _, ev := range expectedEvents {
|
for _, ev := range expectedEvents {
|
||||||
ev.Name = filepath.Join(name, ev.Name)
|
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 _, ok := expected[received]; !ok {
|
||||||
if allowOthers {
|
if len(allowedEvents) > 0 {
|
||||||
sleepMs(100) // To facilitate overflow
|
sleepMs(100) // To facilitate overflow
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user