MCPcopy Index your code
hub / github.com/cortexproject/cortex / Test_newRulerClientFactory

Function Test_newRulerClientFactory

pkg/ruler/client_pool_test.go:20–63  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18)
19
20func Test_newRulerClientFactory(t *testing.T) {
21 // Create a GRPC server used to query the mocked service.
22 grpcServer := grpc.NewServer()
23 defer grpcServer.GracefulStop()
24
25 srv := &mockRulerServer{}
26 RegisterRulerServer(grpcServer, srv)
27
28 listener, err := net.Listen("tcp", "localhost:0")
29 require.NoError(t, err)
30
31 go func() {
32 require.NoError(t, grpcServer.Serve(listener))
33 }()
34
35 // Create a client factory and query back the mocked service
36 // with different clients.
37 cfg := grpcclient.Config{}
38 flagext.DefaultValues(&cfg)
39
40 reg := prometheus.NewPedanticRegistry()
41 factory := newRulerClientFactory(cfg, reg)
42
43 for range 2 {
44 client, err := factory(listener.Addr().String())
45 require.NoError(t, err)
46 defer client.Close() //nolint:errcheck
47
48 ctx := user.InjectOrgID(context.Background(), "test")
49 _, err = client.(*rulerExtendedClient).Rules(ctx, &RulesRequest{})
50 assert.NoError(t, err)
51 }
52
53 // Assert on the request duration metric, but since it's a duration histogram and
54 // we can't predict the exact time it took, we need to workaround it.
55 metrics, err := reg.Gather()
56 require.NoError(t, err)
57
58 assert.Len(t, metrics, 1)
59 assert.Equal(t, "cortex_ruler_client_request_duration_seconds", metrics[0].GetName())
60 assert.Equal(t, dto.MetricType_HISTOGRAM, metrics[0].GetType())
61 assert.Len(t, metrics[0].GetMetric(), 1)
62 assert.Equal(t, uint64(2), metrics[0].GetMetric()[0].GetHistogram().GetSampleCount())
63}
64
65type mockRulerServer struct{}
66

Callers

nothing calls this directly

Calls 12

DefaultValuesFunction · 0.92
RegisterRulerServerFunction · 0.85
newRulerClientFactoryFunction · 0.85
StringMethod · 0.65
CloseMethod · 0.65
RulesMethod · 0.65
EqualMethod · 0.65
LenMethod · 0.45
GetNameMethod · 0.45
GetTypeMethod · 0.45
GetMetricMethod · 0.45
GetHistogramMethod · 0.45

Tested by

no test coverage detected