MCPcopy
hub / github.com/tinode/chat / TestHandleBroadcastInfoChannelWithMultipleReaders

Function TestHandleBroadcastInfoChannelWithMultipleReaders

server/topic_test.go:2920–2976  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2918}
2919
2920func TestHandleBroadcastInfoChannelWithMultipleReaders(t *testing.T) {
2921 topicName := "grpTest"
2922 chanName := "chnTest"
2923 numUsers := 5
2924 helper := TopicTestHelper{}
2925 helper.setUp(t, numUsers, types.TopicCatGrp, topicName, true)
2926 helper.topic.isChan = true
2927 defer helper.tearDown()
2928 helper.topic.lastID = 15
2929
2930 readId := 12
2931 from := helper.uids[0]
2932
2933 // Set up multiple channel readers
2934 for i := 1; i < numUsers; i++ {
2935 uid := helper.uids[i]
2936 pud := helper.topic.perUser[uid]
2937 pud.modeGiven = types.ModeCChnReader
2938 pud.isChan = true
2939 helper.topic.perUser[uid] = pud
2940 }
2941
2942 helper.ss.EXPECT().Update(chanName, from, map[string]any{"ReadSeqId": readId}).Return(nil)
2943
2944 msg := &ClientComMessage{
2945 AsUser: from.UserId(),
2946 Original: chanName,
2947 Note: &MsgClientNote{
2948 Topic: chanName,
2949 What: "read",
2950 SeqId: readId,
2951 },
2952 sess: helper.sessions[0],
2953 }
2954 helper.topic.handleClientMsg(msg)
2955 helper.finish()
2956
2957 // Check for errors from testHubLoop
2958 if errorMsgs, hasError := helper.hubMessages["__ERROR__"]; hasError {
2959 t.Fatal(errorMsgs[0].Ctrl.Text)
2960 }
2961
2962 // Channel topics don't forward note messages to other users
2963 for i, r := range helper.results {
2964 if numMessages := len(r.messages); numMessages != 0 {
2965 t.Errorf("User %d is not expected to receive any messages, %d received", i, numMessages)
2966 }
2967 }
2968
2969 // Only sender gets presence notification
2970 if len(helper.hubMessages) != 1 {
2971 t.Fatalf("Hub expected exactly 1 recipient, got %d", len(helper.hubMessages))
2972 }
2973 if _, ok := helper.hubMessages[from.UserId()]; !ok {
2974 t.Fatal("Expected presence notification for sender")
2975 }
2976}
2977

Callers

nothing calls this directly

Calls 7

setUpMethod · 0.95
tearDownMethod · 0.95
finishMethod · 0.95
UserIdMethod · 0.80
handleClientMsgMethod · 0.80
UpdateMethod · 0.65
EXPECTMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…