| 584 | } |
| 585 | |
| 586 | func (f *notifyFixture) fsyncWithRetryCount(retryCount int) { |
| 587 | if len(f.paths) == 0 { |
| 588 | return |
| 589 | } |
| 590 | |
| 591 | syncPathBase := fmt.Sprintf("sync-%d.txt", time.Now().UnixNano()) |
| 592 | syncPath := filepath.Join(f.paths[0], syncPathBase) |
| 593 | anySyncPath := filepath.Join(f.paths[0], "sync-") |
| 594 | timeout := time.After(250 * time.Second) |
| 595 | |
| 596 | f.WriteFile(syncPath, time.Now().String()) |
| 597 | |
| 598 | F: |
| 599 | for { |
| 600 | select { |
| 601 | case <-f.ctx.Done(): |
| 602 | return |
| 603 | case err := <-f.notify.Errors(): |
| 604 | f.T().Fatal(err) |
| 605 | |
| 606 | case event := <-f.notify.Events(): |
| 607 | if strings.Contains(string(event), syncPath) { |
| 608 | break F |
| 609 | } |
| 610 | if strings.Contains(string(event), anySyncPath) { |
| 611 | continue |
| 612 | } |
| 613 | |
| 614 | // Don't bother tracking duplicate changes to the same path |
| 615 | // for testing. |
| 616 | if len(f.events) > 0 && f.events[len(f.events)-1] == event { |
| 617 | continue |
| 618 | } |
| 619 | |
| 620 | f.events = append(f.events, event) |
| 621 | |
| 622 | case <-timeout: |
| 623 | if retryCount <= 0 { |
| 624 | f.T().Fatalf("fsync: timeout") |
| 625 | } else { |
| 626 | f.fsyncWithRetryCount(retryCount - 1) |
| 627 | } |
| 628 | return |
| 629 | } |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | func (f *notifyFixture) closeWatcher() { |
| 634 | notify := f.notify |