(t *testing.T)
| 933 | } |
| 934 | |
| 935 | func TestDispatchNote(t *testing.T) { |
| 936 | uid := types.Uid(1) |
| 937 | s := test_makeSession(uid) |
| 938 | wg := sync.WaitGroup{} |
| 939 | r := responses{} |
| 940 | wg.Add(1) |
| 941 | go s.testWriteLoop(&r, &wg) |
| 942 | |
| 943 | destUid := types.Uid(2) |
| 944 | topicName := uid.P2PName(destUid) |
| 945 | |
| 946 | brdcst := make(chan *ClientComMessage, 1) |
| 947 | s.subs = make(map[string]*Subscription) |
| 948 | s.subs[topicName] = &Subscription{ |
| 949 | broadcast: brdcst, |
| 950 | } |
| 951 | |
| 952 | msg := &ClientComMessage{ |
| 953 | Note: &MsgClientNote{ |
| 954 | Topic: destUid.UserId(), |
| 955 | What: "recv", |
| 956 | SeqId: 5, |
| 957 | }, |
| 958 | } |
| 959 | |
| 960 | s.dispatch(msg) |
| 961 | close(s.send) |
| 962 | wg.Wait() |
| 963 | |
| 964 | // Check we've routed the join request via the broadcast channel. |
| 965 | if len(r.messages) != 0 { |
| 966 | t.Errorf("responses: expected 0, received %d.", len(r.messages)) |
| 967 | } |
| 968 | if len(brdcst) == 1 { |
| 969 | req := <-brdcst |
| 970 | if req.sess != s { |
| 971 | t.Error("Pub request: sess field expected to be the session under test.") |
| 972 | } |
| 973 | if req.Note.What != msg.Note.What { |
| 974 | t.Errorf("Note request what: expected '%s' vs '%s'.", msg.Note.What, req.Note.What) |
| 975 | } |
| 976 | if req.Note.SeqId != msg.Note.SeqId { |
| 977 | t.Errorf("Note request seqId: expected %d vs %d.", msg.Note.SeqId, req.Note.SeqId) |
| 978 | } |
| 979 | if req.Note.Topic != destUid.UserId() { |
| 980 | t.Errorf("Note request topic: expected '%s' vs '%s'.", destUid.UserId(), req.Note.Topic) |
| 981 | } |
| 982 | } else { |
| 983 | t.Errorf("Note messages: expected 1, received %d.", len(brdcst)) |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | func TestDispatchNoteBroadcastChanFull(t *testing.T) { |
| 988 | uid := types.Uid(1) |
nothing calls this directly
no test coverage detected
searching dependent graphs…