MCPcopy
hub / github.com/daptin/daptin / TestWebSocketMultiTopicSubscribe

Function TestWebSocketMultiTopicSubscribe

websocket_test.go:1268–1311  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1266}
1267
1268func TestWebSocketMultiTopicSubscribe(t *testing.T) {
1269 ensureServer()
1270 token := signUpAndGetToken(t)
1271
1272 const numTopics = 50
1273
1274 ws := dialWS(t, token)
1275 defer ws.Close()
1276
1277 // create N topics
1278 topicNames := make([]string, numTopics)
1279 for i := 0; i < numTopics; i++ {
1280 topicNames[i] = fmt.Sprintf("multi-%d-%d", time.Now().UnixNano(), i)
1281 sendJSON(t, ws, wsPayload{Id: nextReqId(), Method: "create-topicName", Payload: map[string]interface{}{"name": topicNames[i]}})
1282 recvJSON(t, ws, 5*time.Second) // create response
1283 }
1284 time.Sleep(300 * time.Millisecond)
1285
1286 // subscribe to all via comma-separated list
1287 allTopics := ""
1288 for i, name := range topicNames {
1289 if i > 0 {
1290 allTopics += ","
1291 }
1292 allTopics += name
1293 }
1294 sendJSON(t, ws, wsPayload{Id: nextReqId(), Method: "subscribe", Payload: map[string]interface{}{"topicName": allTopics}})
1295
1296 // should get N subscribe responses
1297 ackCount := 0
1298 for i := 0; i < numTopics; i++ {
1299 msg, ok := tryRecvJSON(ws, 5*time.Second)
1300 if !ok {
1301 break
1302 }
1303 if msg.Type == "response" && msg.Ok != nil && *msg.Ok && msg.Method == "subscribe" {
1304 ackCount++
1305 }
1306 }
1307 t.Logf("received %d/%d subscribe acks", ackCount, numTopics)
1308 if ackCount != numTopics {
1309 t.Errorf("expected %d acks, got %d", numTopics, ackCount)
1310 }
1311}
1312
1313func TestWebSocketRapidConnectDisconnect(t *testing.T) {
1314 ensureServer()

Callers

nothing calls this directly

Calls 9

ensureServerFunction · 0.85
signUpAndGetTokenFunction · 0.85
dialWSFunction · 0.85
makeFunction · 0.85
sendJSONFunction · 0.85
nextReqIdFunction · 0.85
recvJSONFunction · 0.85
tryRecvJSONFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected