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

Function TestJSONStats

ptp/sptp/client/json_stats_test.go:45–89  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

43}
44
45func TestJSONStats(t *testing.T) {
46 stats, err := NewJSONStats()
47 require.NoError(t, err)
48 port, err := getFreePort()
49 require.Nil(t, err, "Failed to allocate port")
50 url := fmt.Sprintf("http://localhost:%d", port)
51 go stats.Start(port, time.Second)
52 time.Sleep(time.Second)
53
54 stats.SetTickDuration(time.Millisecond)
55
56 gm0 := &gmstats.Stat{
57 GMAddress: "192.168.0.10",
58 Error: "mymy",
59 }
60 stats.SetGMStats(gm0)
61
62 gm1 := &gmstats.Stat{
63 GMAddress: "192.168.0.13",
64 Error: "",
65 GMPresent: 1,
66 IngressTime: 1676997604198536785,
67 MeanPathDelay: float64(299995 * time.Microsecond),
68 Offset: float64(-100001 * time.Microsecond),
69 PortIdentity: "000000.0086.09c621",
70 Priority1: 1,
71 Priority2: 2,
72 Priority3: 3,
73 Selected: true,
74 StepsRemoved: 1,
75 CorrectionFieldRX: int64(6 * time.Microsecond),
76 CorrectionFieldTX: int64(4 * time.Microsecond),
77 }
78 stats.SetGMStats(gm1)
79
80 require.NoError(t, err)
81
82 gms, err := gmstats.FetchStats(url)
83 require.NoError(t, err)
84 expectedStats := gmstats.Stats{
85 gm0,
86 gm1,
87 }
88 require.Equal(t, expectedStats, gms)
89}
90
91func TestHeaders(t *testing.T) {
92 stats, err := NewJSONStats()

Callers

nothing calls this directly

Calls 6

StartMethod · 0.95
NewJSONStatsFunction · 0.70
getFreePortFunction · 0.70
SetTickDurationMethod · 0.65
SetGMStatsMethod · 0.65
FetchStatsMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…