MCPcopy
hub / github.com/syncthing/syncthing / TestClusterConfigFirst

Function TestClusterConfigFirst

lib/protocol/protocol_test.go:190–232  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

188}
189
190func TestClusterConfigFirst(t *testing.T) {
191 m := newTestModel()
192
193 rw := testutil.NewBlockingRW()
194 c := getRawConnection(NewConnection(c0ID, rw, &testutil.NoopRW{}, testutil.NoopCloser{}, m, new(mockedConnectionInfo), CompressionAlways, testKeyGen))
195 c.Start()
196 defer closeAndWait(c, rw)
197
198 select {
199 case c.outbox <- asyncMessage{&bep.Ping{}, nil}:
200 t.Fatal("able to send ping before cluster config")
201 case <-time.After(100 * time.Millisecond):
202 // Allow some time for c.writerLoop to set up after c.Start
203 }
204
205 c.ClusterConfig(&ClusterConfig{}, nil)
206
207 done := make(chan struct{})
208 if ok := c.send(context.Background(), &bep.Ping{}, done); !ok {
209 t.Fatal("send ping after cluster config returned false")
210 }
211 select {
212 case <-done:
213 case <-time.After(time.Second):
214 t.Fatal("timed out before ping was sent")
215 }
216
217 done = make(chan struct{})
218 go func() {
219 c.internalClose(errManual)
220 close(done)
221 }()
222
223 select {
224 case <-done:
225 case <-time.After(5 * time.Second):
226 t.Fatal("Close didn't return before timeout")
227 }
228
229 if err := m.closedError(); err != errManual {
230 t.Fatal("Connection should be closed")
231 }
232}
233
234// TestCloseTimeout checks that calling Close times out and proceeds, if sending
235// the close message does not succeed.

Callers

nothing calls this directly

Calls 11

NewBlockingRWFunction · 0.92
newTestModelFunction · 0.85
getRawConnectionFunction · 0.85
NewConnectionFunction · 0.85
closeAndWaitFunction · 0.85
FatalMethod · 0.80
internalCloseMethod · 0.80
closedErrorMethod · 0.80
StartMethod · 0.65
ClusterConfigMethod · 0.65
sendMethod · 0.65

Tested by

no test coverage detected