MCPcopy
hub / github.com/zalando/skipper / TestInitOrderAndDefault

Function TestInitOrderAndDefault

metricsinit_test.go:36–97  ·  view source on GitHub ↗

Initialization order of the metrics.Default global must be done before other packages may start to use it.

(t *testing.T)

Source from the content-addressed store, hash-verified

34
35// Initialization order of the metrics.Default global must be done before other packages may start to use it.
36func TestInitOrderAndDefault(t *testing.T) {
37 const (
38 ringMetricsUpdatePeriod = time.Millisecond
39 testTimeout = 5 * time.Second
40 )
41
42 port := mustAvailablePort(t)
43 supportPort := mustAvailablePort(t)
44 redisPort := mustAvailablePort(t)
45 sig := make(chan os.Signal, 1)
46 done := make(chan struct{})
47 go func() {
48 options := Options{
49 Address: fmt.Sprintf(":%d", port),
50 SupportListener: fmt.Sprintf(":%d", supportPort),
51 EnableRuntimeMetrics: true,
52 EnableSwarm: true,
53 SwarmRedisURLs: []string{fmt.Sprintf("localhost:%d", redisPort)},
54 EnableRatelimiters: true,
55 SwarmRedisConnMetricsInterval: ringMetricsUpdatePeriod,
56 PassiveHealthCheck: map[string]string{
57 "period": "1m",
58 "min-requests": "10",
59 "max-drop-probability": "0.9",
60 "min-drop-probability": "0.05",
61 },
62 }
63
64 tornDown := make(chan struct{})
65 if err := run(options, sig, tornDown); err != nil {
66 t.Error(err)
67 }
68
69 <-tornDown
70 close(done)
71 }()
72
73 to := time.After(testTimeout)
74 func() {
75 for {
76 rsp, err := http.Get(fmt.Sprintf("http://localhost:%d/metrics/swarm", supportPort))
77 if err != nil {
78 t.Log("error making request", err)
79 } else {
80 rsp.Body.Close()
81 if rsp.StatusCode == http.StatusOK {
82 return
83 }
84 }
85
86 select {
87 case <-time.After(ringMetricsUpdatePeriod):
88 case <-to:
89 t.Error("test timeout")
90 return
91 }
92 }
93 }()

Callers

nothing calls this directly

Calls 6

mustAvailablePortFunction · 0.85
LogMethod · 0.80
runFunction · 0.70
ErrorMethod · 0.65
GetMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…