(b *testing.B)
| 1863 | } |
| 1864 | |
| 1865 | func BenchmarkWebSocketFanOut(b *testing.B) { |
| 1866 | ensureServer() |
| 1867 | token := signUpAndGetToken(b) |
| 1868 | |
| 1869 | const numSubs = 10 |
| 1870 | |
| 1871 | topicName := fmt.Sprintf("bench-fo-%d", time.Now().UnixNano()) |
| 1872 | wsPub := dialWS(b, token) |
| 1873 | defer wsPub.Close() |
| 1874 | |
| 1875 | sendJSON(b, wsPub, wsPayload{Id: nextReqId(), Method: "create-topicName", Payload: map[string]interface{}{"name": topicName}}) |
| 1876 | recvJSON(b, wsPub, 5*time.Second) // create response |
| 1877 | time.Sleep(300 * time.Millisecond) |
| 1878 | |
| 1879 | subs := make([]*websocket.Conn, numSubs) |
| 1880 | for i := 0; i < numSubs; i++ { |
| 1881 | subs[i] = dialWS(b, token) |
| 1882 | sendJSON(b, subs[i], wsPayload{Id: nextReqId(), Method: "subscribe", Payload: map[string]interface{}{"topicName": topicName}}) |
| 1883 | recvJSON(b, subs[i], 5*time.Second) // subscribe ack |
| 1884 | } |
| 1885 | |
| 1886 | b.ResetTimer() |
| 1887 | for i := 0; i < b.N; i++ { |
| 1888 | sendJSON(b, wsPub, wsPayload{ |
| 1889 | Method: "new-message", |
| 1890 | Payload: map[string]interface{}{ |
| 1891 | "topicName": topicName, |
| 1892 | "message": map[string]interface{}{"seq": i}, |
| 1893 | }, |
| 1894 | }) |
| 1895 | for _, sub := range subs { |
| 1896 | recvJSON(b, sub, 10*time.Second) |
| 1897 | } |
| 1898 | } |
| 1899 | b.StopTimer() |
| 1900 | |
| 1901 | for _, s := range subs { |
| 1902 | s.Close() |
| 1903 | } |
| 1904 | } |
| 1905 | |
| 1906 | func BenchmarkWebSocketConnect(b *testing.B) { |
| 1907 | ensureServer() |
nothing calls this directly
no test coverage detected