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

Function TestWriteRequest_Sign

pkg/cortexpb/extensions_test.go:38–86  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

36}
37
38func TestWriteRequest_Sign(t *testing.T) {
39 ctx := context.Background()
40 ctx = user.InjectOrgID(ctx, "user-1")
41
42 tests := map[string]struct {
43 w *WriteRequest
44 expectedSign string
45 }{
46 "small write with exemplar": {
47 w: createWriteRequest(10, true, "family1", "help1", "unit"),
48 expectedSign: "v1/9125893422459502203",
49 },
50 "small write with exemplar and changed md": {
51 w: createWriteRequest(10, true, "family2", "help1", "unit"),
52 expectedSign: "v1/18044786562323437562",
53 },
54 "small write without exemplar": {
55 w: createWriteRequest(10, false, "family1", "help1", "unit"),
56 expectedSign: "v1/7697478040597284323",
57 },
58 "big write with exemplar": {
59 w: createWriteRequest(10000, true, "family1", "help1", "unit"),
60 expectedSign: "v1/18402783317092766507",
61 },
62 "big write without exemplar": {
63 w: createWriteRequest(10000, false, "family1", "help1", "unit"),
64 expectedSign: "v1/14973071954515615892",
65 },
66 }
67
68 for name, tc := range tests {
69 t.Run(name, func(t *testing.T) {
70 // running multiple times in parallel to make sure no race
71 itNumber := 1000
72 wg := sync.WaitGroup{}
73 wg.Add(itNumber)
74 for range itNumber {
75 go func() {
76 defer wg.Done()
77 s, err := tc.w.Sign(ctx)
78 require.NoError(t, err)
79 // Make sure this sign doesn't change
80 require.Equal(t, tc.expectedSign, s)
81 }()
82 }
83 wg.Wait()
84 })
85 }
86}
87
88func createWriteRequest(numTs int, exemplar bool, family string, help string, unit string) *WriteRequest {
89 w := &WriteRequest{}

Callers

nothing calls this directly

Calls 7

createWriteRequestFunction · 0.85
DoneMethod · 0.80
RunMethod · 0.65
SignMethod · 0.65
EqualMethod · 0.65
AddMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected