(t *testing.T)
| 175 | } |
| 176 | |
| 177 | func TestSyncDesync(t *testing.T) { |
| 178 | ln, client, server, dispatcher, err := newSyncTest() |
| 179 | if err != nil { |
| 180 | t.Fatal(err) |
| 181 | } |
| 182 | defer ln.Close() |
| 183 | |
| 184 | // Switch the dispatcher to a blocking channel. |
| 185 | dispatcher.notes = make(chan *SyncNote) |
| 186 | |
| 187 | go client.runOnce() |
| 188 | defer func() { |
| 189 | close(client.quit) |
| 190 | for { |
| 191 | // Drain the notes to unblock the quit reader. |
| 192 | if _, err := dispatcher.nextNote(); err != nil { |
| 193 | break |
| 194 | } |
| 195 | } |
| 196 | <-client.stopped |
| 197 | }() |
| 198 | |
| 199 | // The server should send a desync at the start of the session. |
| 200 | n, err := dispatcher.nextNote() |
| 201 | if err != nil { |
| 202 | t.Fatalf("Expected desync, got error: %v", err) |
| 203 | } |
| 204 | if n.Type != SNTDesync { |
| 205 | t.Fatalf("Got %v, want %v", n.Type, SNTDesync) |
| 206 | } |
| 207 | |
| 208 | // Send a single notification to complete the poll. |
| 209 | server.notify(&SyncNote{Type: SNTHeartbeat}) |
| 210 | time.Sleep(250 * time.Millisecond) |
| 211 | // syncClient.poll should now be blocked writing that Note to |
| 212 | // testNoteDispatcher's notes chan. |
| 213 | |
| 214 | // Send enough notifications to fill the session channel buffer. |
| 215 | server.notify(&SyncNote{Type: SNTHeartbeat}) |
| 216 | server.notify(&SyncNote{Type: SNTConfigUpdate}) |
| 217 | for i := 0; i < (sessionNotesQueueSize * 1.1); i++ { |
| 218 | server.notify(&SyncNote{Type: SNTHealthcheck}) |
| 219 | } |
| 220 | |
| 221 | // Now we unblock syncClient.poll by reading the initial notification from |
| 222 | // the local chan. At that point, it should do another Poll and see the |
| 223 | // desync. |
| 224 | received := make(map[SyncNoteType]int) |
| 225 | noteLoop: |
| 226 | for i := 0; i < (sessionNotesQueueSize * 1.1); i++ { |
| 227 | n, err := dispatcher.nextNote() |
| 228 | if err != nil { |
| 229 | t.Fatalf("nextNote() failed: %v; expected note", err) |
| 230 | } |
| 231 | received[n.Type]++ |
| 232 | |
| 233 | switch n.Type { |
| 234 | case SNTHeartbeat, SNTHealthcheck: // ok |
nothing calls this directly
no test coverage detected