MCPcopy
hub / github.com/docker/compose / fsyncWithRetryCount

Method fsyncWithRetryCount

pkg/watch/notify_test.go:586–631  ·  view source on GitHub ↗
(retryCount int)

Source from the content-addressed store, hash-verified

584}
585
586func (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
598F:
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
633func (f *notifyFixture) closeWatcher() {
634 notify := f.notify

Callers 1

fsyncMethod · 0.95

Calls 6

WriteFileMethod · 0.80
TMethod · 0.80
DoneMethod · 0.65
ErrorsMethod · 0.65
EventsMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected