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

Function TestFetchStats

fbclock/daemon/datafetcher_http_test.go:52–74  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

50 fetcher := &HTTPFetcher{}
51 hosts, err := fetcher.FetchGMs(cfg)
52 require.Nil(t, err)
53 require.Equal(t, []string{"127.0.0.1"}, hosts)
54}
55
56func TestFetchStats(t *testing.T) {
57 sampleResp := `
58[
59 {"gm_address": "127.0.0.1", "selected": false, "port_identity": "oleg", "clock_quality": {"clock_class": 6, "clock_accuracy": 33, "offset_scaled_log_variance": 42}, "priority1": 2, "priority2": 3, "priority3": 4, "offset": -42.42, "mean_path_delay": 42.42, "steps_removed": 3, "gm_present": 1, "error": ""},
60 {"gm_address": "::1", "selected": true, "port_identity": "oleg1", "clock_quality": {"clock_class": 7, "clock_accuracy": 34, "offset_scaled_log_variance": 42}, "priority1": 2, "priority2": 3, "priority3": 4, "offset": -43.43, "mean_path_delay": 43.43, "steps_removed": 3, "gm_present": 1, "servo_state": 2}
61]
62`
63 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
64 fmt.Fprintln(w, sampleResp)
65 }))
66 defer ts.Close()
67 surl, err := url.Parse(ts.URL)
68 require.Nil(t, err)
69 target := fmt.Sprintf("%s:%s", surl.Hostname(), surl.Port())
70 cfg := &Config{
71 PTPClientAddress: target,
72 }
73 fetcher := &HTTPFetcher{}
74 sstats, err := fetcher.FetchStats(cfg)
75 require.Nil(t, err)
76 expected := DataPoint{IngressTimeNS: 0, MasterOffsetNS: -43.43, PathDelayNS: 43.43, FreqAdjustmentPPB: 0, ClockAccuracyNS: 250, ServoState: 2}
77 require.Equal(t, sstats, &expected)

Callers

nothing calls this directly

Calls 2

FetchStatsMethod · 0.95
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…