MCPcopy Create free account
hub / github.com/facebook/time / TestJSONStatsHTTPEndpoint

Function TestJSONStatsHTTPEndpoint

cmd/ntripper/stats/json_test.go:40–61  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

38}
39
40func TestJSONStatsHTTPEndpoint(t *testing.T) {
41 st := NewJSONStats()
42
43 st.SetConnected(1)
44
45 // Manually set the rate.
46 st.framesPerSecond.Store(42)
47
48 rec := httptest.NewRecorder()
49 req := httptest.NewRequest(http.MethodGet, "/", nil)
50 st.handleRequest(rec, req)
51
52 require.Equal(t, http.StatusOK, rec.Code)
53 require.Equal(t, "application/json", rec.Header().Get("Content-Type"))
54
55 var snap snapshot
56 err := json.Unmarshal(rec.Body.Bytes(), &snap)
57 require.NoError(t, err)
58
59 require.Equal(t, int64(42), snap.FramesPerSecond)
60 require.Equal(t, int64(1), snap.Connected)
61}
62
63func TestJSONStatsFramesPerSecond(t *testing.T) {
64 st := NewJSONStats()

Callers

nothing calls this directly

Calls 5

SetConnectedMethod · 0.95
handleRequestMethod · 0.95
NewJSONStatsFunction · 0.70
GetMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…