(t *testing.T)
| 55 | var errManual = errors.New("manual close") |
| 56 | |
| 57 | func 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). |
nothing calls this directly
no test coverage detected