(t *testing.T)
| 17 | ) |
| 18 | |
| 19 | func TestWaitSumMetric(t *testing.T) { |
| 20 | // Listen on a random port before starting the HTTP server, to |
| 21 | // make sure the port is already open when we'll call WaitSumMetric() |
| 22 | // the first time (this avoid flaky tests). |
| 23 | ln, err := net.Listen("tcp", "localhost:0") |
| 24 | require.NoError(t, err) |
| 25 | defer ln.Close() |
| 26 | |
| 27 | // Get the port. |
| 28 | _, addrPort, err := net.SplitHostPort(ln.Addr().String()) |
| 29 | require.NoError(t, err) |
| 30 | |
| 31 | port, err := strconv.Atoi(addrPort) |
| 32 | require.NoError(t, err) |
| 33 | |
| 34 | // Start an HTTP server exposing the metrics. |
| 35 | srv := &http.Server{ |
| 36 | Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 37 | _, _ = w.Write([]byte(` |
| 38 | # HELP metric_c cheescake |
| 39 | # TYPE metric_c gauge |
| 40 | metric_c 20 |
| 41 | # HELP metric_a cheescake |
| 42 | # TYPE metric_a gauge |
| 43 | metric_a 1 |
| 44 | metric_a{first="value1"} 10 |
| 45 | metric_a{first="value1", something="x"} 4 |
| 46 | metric_a{first="value1", something2="a"} 203 |
| 47 | metric_a{first="value2"} 2 |
| 48 | metric_a{second="value1"} 1 |
| 49 | # HELP metric_b cheescake |
| 50 | # TYPE metric_b gauge |
| 51 | metric_b 1000 |
| 52 | # HELP metric_b_counter cheescake |
| 53 | # TYPE metric_b_counter counter |
| 54 | metric_b_counter 1020 |
| 55 | # HELP metric_b_hist cheescake |
| 56 | # TYPE metric_b_hist histogram |
| 57 | metric_b_hist_count 5 |
| 58 | metric_b_hist_sum 124 |
| 59 | metric_b_hist_bucket{le="5.36870912e+08"} 1 |
| 60 | metric_b_hist_bucket{le="+Inf"} 5 |
| 61 | # HELP metric_b_summary cheescake |
| 62 | # TYPE metric_b_summary summary |
| 63 | metric_b_summary_sum 22 |
| 64 | metric_b_summary_count 1 |
| 65 | `)) |
| 66 | }), |
| 67 | } |
| 68 | defer srv.Close() |
| 69 | |
| 70 | go func() { |
| 71 | _ = srv.Serve(ln) |
| 72 | }() |
| 73 | |
| 74 | s := &HTTPService{ |
| 75 | httpPort: 0, |
| 76 | ConcreteService: &ConcreteService{ |
nothing calls this directly
no test coverage detected