MCPcopy
hub / github.com/syncthing/syncthing / TestClose

Function TestClose

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

Source from the content-addressed store, hash-verified

55var errManual = errors.New("manual close")
56
57func TestClose(t *testing.T) {
58 m0 := newTestModel()
59 m1 := newTestModel()
60
61 ar, aw := io.Pipe()
62 br, bw := io.Pipe()
63
64 c0 := getRawConnection(NewConnection(c0ID, ar, bw, testutil.NoopCloser{}, m0, new(mockedConnectionInfo), CompressionAlways, testKeyGen))
65 c0.Start()
66 defer closeAndWait(c0, ar, bw)
67 c1 := NewConnection(c1ID, br, aw, testutil.NoopCloser{}, m1, new(mockedConnectionInfo), CompressionAlways, testKeyGen)
68 c1.Start()
69 defer closeAndWait(c1, ar, bw)
70 c0.ClusterConfig(&ClusterConfig{}, nil)
71 c1.ClusterConfig(&ClusterConfig{}, nil)
72
73 c0.internalClose(errManual)
74
75 <-c0.closed
76 if err := m0.closedError(); err != errManual {
77 t.Fatal("Connection should be closed")
78 }
79
80 // None of these should panic, some should return an error
81
82 if c0.ping() {
83 t.Error("Ping should not return true")
84 }
85
86 ctx := context.Background()
87
88 c0.Index(ctx, &Index{Folder: "default"})
89 c0.Index(ctx, &Index{Folder: "default"})
90
91 if _, err := c0.Request(ctx, &Request{Folder: "default", Name: "foo"}); err == nil {
92 t.Error("Request should return an error")
93 }
94}
95
96// TestCloseOnBlockingSend checks that the connection does not deadlock when
97// Close is called while the underlying connection is broken (send blocks).

Callers

nothing calls this directly

Calls 14

StartMethod · 0.95
ClusterConfigMethod · 0.95
newTestModelFunction · 0.85
getRawConnectionFunction · 0.85
NewConnectionFunction · 0.85
closeAndWaitFunction · 0.85
internalCloseMethod · 0.80
closedErrorMethod · 0.80
FatalMethod · 0.80
pingMethod · 0.80
ClusterConfigMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected