MCPcopy
hub / github.com/grafana/tempo / TestHedge

Function TestHedge

tempodb/backend/azure/azure_test.go:46–135  ·  tempodb/backend/azure/azure_test.go::TestHedge
(t *testing.T)

Source from the content-addressed store, hash-verified

44}
45
46func TestHedge(t *testing.T) {
47 tests := []struct {
48 name string
49 returnIn time.Duration
50 hedgeAt time.Duration
51 expectedHedgedRequests int32
52 }{
53 {
54 name: "hedge disabled",
55 expectedHedgedRequests: 1,
56 },
57 {
58 name: "hedge enabled doesn't hit",
59 hedgeAt: time.Hour,
60 expectedHedgedRequests: 1,
61 },
62 {
63 name: "hedge enabled and hits",
64 hedgeAt: time.Millisecond,
65 returnIn: 100 * time.Millisecond,
66 expectedHedgedRequests: 2,
67 },
68 }
69
70 for _, tc := range tests {
71 t.Run(tc.name, func(t *testing.T) {
72 count := int32(0)
73 server := fakeServer(t, tc.returnIn, &count)
74
75 r, w, _, err := New(&Config{
76 StorageAccountName: "testing",
77 StorageAccountKey: flagext.SecretWithValue("YQo="),
78 MaxBuffers: 3,
79 BufferSize: 1000,
80 ContainerName: "blerg",
81 Endpoint: server.URL[7:], // [7:] -> strip http://,
82 HedgeRequestsAt: tc.hedgeAt,
83 HedgeRequestsUpTo: 2,
84 })
85 require.NoError(t, err)
86
87 ctx := context.Background()
88
89 // the first call on each client initiates an extra http request
90 // clearing that here
91 _, _, _ = r.Read(ctx, "object", backend.KeyPathForBlock(uuid.New(), "tenant"), nil)
92 time.Sleep(tc.returnIn)
93 atomic.StoreInt32(&count, 0)
94
95 // calls that should hedge
96 _, _, _ = r.Read(ctx, "object", backend.KeyPathForBlock(uuid.New(), "tenant"), nil)
97 time.Sleep(tc.returnIn)
98 assert.Equal(t, tc.expectedHedgedRequests*2, atomic.LoadInt32(&count)) // *2 b/c reads execute a HEAD and GET
99 atomic.StoreInt32(&count, 0)
100
101 // this panics with the garbage test setup. todo: make it not panic
102 // _ = r.ReadRange(ctx, "object", uuid.New(), "tenant", 10, make([]byte, 100))
103 // time.Sleep(tc.returnIn)

Callers

nothing calls this directly

Calls 9

KeyPathForBlockFunction · 0.92
fakeServerFunction · 0.70
NewFunction · 0.70
ReadMethod · 0.65
SleepMethod · 0.65
ListMethod · 0.65
WriteMethod · 0.65
RunMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected