MCPcopy
hub / github.com/syncthing/syncthing / TestProgressEmitter

Function TestProgressEmitter

lib/model/progressemitter_test.go:54–111  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

52}
53
54func TestProgressEmitter(t *testing.T) {
55 ctx, cancel := context.WithCancel(context.Background())
56 evLogger := events.NewLogger()
57 go evLogger.Serve(ctx)
58 defer cancel()
59
60 w := evLogger.Subscribe(events.DownloadProgress)
61
62 c, cfgCancel := newConfigWrapper(config.Configuration{Version: config.CurrentVersion})
63 defer os.Remove(c.ConfigPath())
64 defer cfgCancel()
65 waiter, err := c.Modify(func(cfg *config.Configuration) {
66 cfg.Options.ProgressUpdateIntervalS = 60 // irrelevant, but must be positive
67 })
68 if err != nil {
69 t.Fatal(err)
70 }
71 waiter.Wait()
72
73 p := NewProgressEmitter(c, evLogger)
74 go p.Serve(ctx)
75 p.interval = 0
76
77 expectTimeout(w, t)
78
79 s := sharedPullerState{
80 updated: time.Now(),
81 }
82 p.Register(&s)
83
84 expectEvent(w, t, 1)
85 expectTimeout(w, t)
86
87 s.copyDone(protocol.BlockInfo{})
88
89 expectEvent(w, t, 1)
90 expectTimeout(w, t)
91
92 s.copiedFromOrigin(1)
93
94 expectEvent(w, t, 1)
95 expectTimeout(w, t)
96
97 s.pullStarted()
98
99 expectEvent(w, t, 1)
100 expectTimeout(w, t)
101
102 s.pullDone(protocol.BlockInfo{})
103
104 expectEvent(w, t, 1)
105 expectTimeout(w, t)
106
107 p.Deregister(&s)
108
109 expectEvent(w, t, 0)
110 expectTimeout(w, t)
111}

Callers

nothing calls this directly

Calls 15

SubscribeMethod · 0.95
ServeMethod · 0.95
RegisterMethod · 0.95
copyDoneMethod · 0.95
copiedFromOriginMethod · 0.95
pullStartedMethod · 0.95
pullDoneMethod · 0.95
DeregisterMethod · 0.95
NewLoggerFunction · 0.92
newConfigWrapperFunction · 0.85
NewProgressEmitterFunction · 0.85
expectTimeoutFunction · 0.85

Tested by

no test coverage detected