MCPcopy
hub / github.com/syncthing/syncthing / testWatchOutput

Function testWatchOutput

lib/fs/basicfs_watch_test.go:570–608  ·  view source on GitHub ↗
(t *testing.T, name string, in <-chan Event, expectedEvents, allowedEvents []Event, ctx context.Context, cancel context.CancelFunc)

Source from the content-addressed store, hash-verified

568}
569
570func testWatchOutput(t *testing.T, name string, in <-chan Event, expectedEvents, allowedEvents []Event, ctx context.Context, cancel context.CancelFunc) {
571 expected := make(map[Event]struct{})
572 for _, ev := range expectedEvents {
573 ev.Name = filepath.Join(name, ev.Name)
574 expected[ev] = struct{}{}
575 }
576
577 var received Event
578 var last Event
579 for {
580 if len(expected) == 0 {
581 cancel()
582 return
583 }
584
585 select {
586 case <-ctx.Done():
587 return
588 case received = <-in:
589 }
590
591 // apparently the backend sometimes sends repeat events
592 if last == received {
593 continue
594 }
595
596 if _, ok := expected[received]; !ok {
597 if len(allowedEvents) > 0 {
598 sleepMs(100) // To facilitate overflow
599 continue
600 }
601 t.Errorf("Received unexpected event %v expected one of %v", received, expected)
602 cancel()
603 return
604 }
605 delete(expected, received)
606 last = received
607 }
608}
609
610// Matches are done via direct comparison against both ignore and include
611type fakeMatcher struct {

Callers 1

testScenarioFunction · 0.85

Calls 2

DoneMethod · 0.80
sleepMsFunction · 0.70

Tested by

no test coverage detected