MCPcopy
hub / github.com/ory/keto / TestScrapingEndpoint

Function TestScrapingEndpoint

internal/driver/daemon_test.go:27–82  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25)
26
27func TestScrapingEndpoint(t *testing.T) {
28 t.Parallel()
29
30 ctx, cancel := context.WithCancel(context.Background())
31 defer cancel()
32
33 r := NewSqliteTestRegistry(t, false)
34 getAddr := UseDynamicPorts(ctx, t, r)
35
36 eg := errgroup.Group{}
37 doneShutdown := make(chan struct{})
38 eg.Go(r.serveWrite(ctx, doneShutdown))
39 eg.Go(r.serveMetrics(ctx, doneShutdown))
40
41 _, writePort, _ := getAddr(t, "write")
42 _, metricsPort, _ := getAddr(t, "metrics")
43
44 t.Logf("write port: %s, metrics port: %s", writePort, metricsPort)
45
46 assert.EventuallyWithT(t, func(t *assert.CollectT) {
47 conn, err := grpc.NewClient(fmt.Sprintf("127.0.0.1:%s", writePort), grpc.WithTransportCredentials(insecure.NewCredentials()))
48 require.NoError(t, err)
49 defer func() { require.NoError(t, conn.Close()) }()
50
51 cl := grpcHealthV1.NewHealthClient(conn)
52 watcher, err := cl.Watch(ctx, &grpcHealthV1.HealthCheckRequest{})
53 require.NoError(t, err)
54 require.NoError(t, watcher.CloseSend())
55 for err := status.Error(codes.Unavailable, "init"); status.Code(err) != codes.Unavailable; _, err = watcher.Recv() {
56 }
57 }, 2*time.Second, 10*time.Millisecond)
58
59 promresp, err := http.Get(fmt.Sprintf("http://127.0.0.1:%s", metricsPort) + prometheus.MetricsPrometheusPath)
60 require.NoError(t, err)
61 require.EqualValues(t, http.StatusOK, promresp.StatusCode)
62
63 textParser := expfmt.TextParser{}
64 text, err := textParser.TextToMetricFamilies(promresp.Body)
65 require.NoError(t, err)
66 require.EqualValues(t, "grpc_server_handled_total", *text["grpc_server_handled_total"].Name)
67 require.EqualValues(t, "Check", getLabelValue("grpc_method", text["grpc_server_handled_total"].Metric))
68 require.EqualValues(t, "grpc.health.v1.Health", getLabelValue("grpc_service", text["grpc_server_handled_total"].Metric))
69
70 require.EqualValues(t, "grpc_server_msg_sent_total", *text["grpc_server_msg_sent_total"].Name)
71 require.EqualValues(t, "Check", getLabelValue("grpc_method", text["grpc_server_msg_sent_total"].Metric))
72 require.EqualValues(t, "grpc.health.v1.Health", getLabelValue("grpc_service", text["grpc_server_msg_sent_total"].Metric))
73
74 require.EqualValues(t, "grpc_server_msg_received_total", *text["grpc_server_msg_received_total"].Name)
75 require.EqualValues(t, "Check", getLabelValue("grpc_method", text["grpc_server_msg_received_total"].Metric))
76 require.EqualValues(t, "grpc.health.v1.Health", getLabelValue("grpc_service", text["grpc_server_msg_received_total"].Metric))
77
78 cancel()
79 <-doneShutdown
80 <-doneShutdown
81 require.NoError(t, eg.Wait())
82}
83
84func TestPanicRecovery(t *testing.T) {

Callers

nothing calls this directly

Calls 10

NewSqliteTestRegistryFunction · 0.85
UseDynamicPortsFunction · 0.85
getLabelValueFunction · 0.85
serveWriteMethod · 0.80
serveMetricsMethod · 0.80
WatchMethod · 0.80
CloseMethod · 0.65
LogfMethod · 0.45
ErrorMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected