MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestReplicationSet_Do

Function TestReplicationSet_Do

pkg/ring/replication_set_test.go:114–297  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

112}
113
114func TestReplicationSet_Do(t *testing.T) {
115 tests := []struct {
116 name string
117 instances []InstanceDesc
118 maxErrors int
119 maxUnavailableZones int
120 f func(context.Context, *InstanceDesc) (any, error)
121 delay time.Duration
122 cancelContextDelay time.Duration
123 want []any
124 expectedError error
125 zoneResultsQuorum bool
126 queryPartialData bool
127 errStrContains []string
128 }{
129 {
130 name: "max errors = 0, no errors no delay",
131 instances: []InstanceDesc{
132 {},
133 },
134 f: func(c context.Context, id *InstanceDesc) (any, error) {
135 return 1, nil
136 },
137 want: []any{1},
138 },
139 {
140 name: "max errors = 0, should fail on 1 error out of 1 instance",
141 instances: []InstanceDesc{{}},
142 f: func(c context.Context, id *InstanceDesc) (any, error) {
143 return nil, errFailure
144 },
145 want: nil,
146 expectedError: errFailure,
147 },
148 {
149 name: "max errors = 0, should fail on 1 error out of 3 instances (last call fails)",
150 instances: []InstanceDesc{{}, {}, {}},
151 f: failingFunctionAfter(2, 10*time.Millisecond),
152 want: nil,
153 expectedError: errFailure,
154 },
155 {
156 name: "max errors = 1, should fail on 3 errors out of 5 instances (last calls fail)",
157 instances: []InstanceDesc{{}, {}, {}, {}, {}},
158 maxErrors: 1,
159 f: failingFunctionAfter(2, 10*time.Millisecond),
160 delay: 100 * time.Millisecond,
161 want: nil,
162 expectedError: errFailure,
163 },
164 {
165 name: "max errors = 1, should handle context canceled",
166 instances: []InstanceDesc{{}, {}, {}},
167 maxErrors: 1,
168 f: func(c context.Context, id *InstanceDesc) (any, error) {
169 time.Sleep(300 * time.Millisecond)
170 return 1, nil
171 },

Callers

nothing calls this directly

Calls 7

DoMethod · 0.95
LimitErrorTypeAlias · 0.92
failingFunctionAfterFunction · 0.85
failingFunctionOnZonesFunction · 0.85
RunMethod · 0.65
EqualMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected