(t *testing.T)
| 139 | } |
| 140 | |
| 141 | func TestCloseRace(t *testing.T) { |
| 142 | indexReceived := make(chan struct{}) |
| 143 | unblockIndex := make(chan struct{}) |
| 144 | m0 := newTestModel() |
| 145 | m0.indexFn = func(string, []FileInfo) { |
| 146 | close(indexReceived) |
| 147 | <-unblockIndex |
| 148 | } |
| 149 | m1 := newTestModel() |
| 150 | |
| 151 | ar, aw := io.Pipe() |
| 152 | br, bw := io.Pipe() |
| 153 | |
| 154 | c0 := getRawConnection(NewConnection(c0ID, ar, bw, testutil.NoopCloser{}, m0, new(mockedConnectionInfo), CompressionNever, testKeyGen)) |
| 155 | c0.Start() |
| 156 | defer closeAndWait(c0, ar, bw) |
| 157 | c1 := NewConnection(c1ID, br, aw, testutil.NoopCloser{}, m1, new(mockedConnectionInfo), CompressionNever, testKeyGen) |
| 158 | c1.Start() |
| 159 | defer closeAndWait(c1, ar, bw) |
| 160 | c0.ClusterConfig(&ClusterConfig{}, nil) |
| 161 | c1.ClusterConfig(&ClusterConfig{}, nil) |
| 162 | |
| 163 | c1.Index(context.Background(), &Index{Folder: "default"}) |
| 164 | select { |
| 165 | case <-indexReceived: |
| 166 | case <-time.After(time.Second): |
| 167 | t.Fatal("timed out before receiving index") |
| 168 | } |
| 169 | |
| 170 | go c0.internalClose(errManual) |
| 171 | select { |
| 172 | case <-c0.closed: |
| 173 | case <-time.After(time.Second): |
| 174 | t.Fatal("timed out before c0.closed was closed") |
| 175 | } |
| 176 | |
| 177 | select { |
| 178 | case <-m0.closedCh: |
| 179 | t.Errorf("receiver.Closed called before receiver.Index") |
| 180 | default: |
| 181 | } |
| 182 | |
| 183 | close(unblockIndex) |
| 184 | |
| 185 | if err := m0.closedError(); err != errManual { |
| 186 | t.Fatal("Connection should be closed") |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | func TestClusterConfigFirst(t *testing.T) { |
| 191 | m := newTestModel() |
nothing calls this directly
no test coverage detected