(t *testing.T)
| 332 | } |
| 333 | |
| 334 | func TestDispatchLeave(t *testing.T) { |
| 335 | uid := types.Uid(1) |
| 336 | s := test_makeSession(uid) |
| 337 | wg := sync.WaitGroup{} |
| 338 | r := responses{} |
| 339 | wg.Add(1) |
| 340 | go s.testWriteLoop(&r, &wg) |
| 341 | |
| 342 | destUid := types.Uid(2) |
| 343 | topicName := uid.P2PName(destUid) |
| 344 | leave := make(chan *ClientComMessage, 1) |
| 345 | s.subs = make(map[string]*Subscription) |
| 346 | s.subs[topicName] = &Subscription{ |
| 347 | done: leave, |
| 348 | } |
| 349 | |
| 350 | msg := &ClientComMessage{ |
| 351 | Leave: &MsgClientLeave{ |
| 352 | Id: "123", |
| 353 | Topic: destUid.UserId(), |
| 354 | }, |
| 355 | } |
| 356 | |
| 357 | s.dispatch(msg) |
| 358 | close(s.send) |
| 359 | wg.Wait() |
| 360 | |
| 361 | // Check we've routed the join request via the leave channel. |
| 362 | if len(r.messages) != 0 { |
| 363 | t.Errorf("responses: expected 0, received %d.", len(r.messages)) |
| 364 | } |
| 365 | if len(leave) == 1 { |
| 366 | req := <-leave |
| 367 | if req.sess != s { |
| 368 | t.Error("Leave request: sess field expected to be the session under test.") |
| 369 | } |
| 370 | if req != msg { |
| 371 | t.Error("Leave request: leave message expected to be the original leave message.") |
| 372 | } |
| 373 | // leave request handler is expected to clean up subs. |
| 374 | s.delSub(topicName) |
| 375 | } else { |
| 376 | t.Errorf("Unsub messages: expected 1, received %d.", len(leave)) |
| 377 | } |
| 378 | if len(s.subs) != 0 { |
| 379 | t.Errorf("Session subs: expected to be empty, actual size: %d", len(s.subs)) |
| 380 | } |
| 381 | s.inflightReqs.Done() |
| 382 | } |
| 383 | |
| 384 | func TestDispatchLeaveUnsubMe(t *testing.T) { |
| 385 | uid := types.Uid(1) |
nothing calls this directly
no test coverage detected
searching dependent graphs…