(t *testing.T)
| 2282 | } |
| 2283 | |
| 2284 | func TestRing_ShuffleShardWithLookback(t *testing.T) { |
| 2285 | type eventType int |
| 2286 | |
| 2287 | const ( |
| 2288 | add eventType = iota |
| 2289 | remove |
| 2290 | test |
| 2291 | |
| 2292 | lookbackPeriod = time.Hour |
| 2293 | userID = "user-1" |
| 2294 | ) |
| 2295 | |
| 2296 | var ( |
| 2297 | now = time.Now() |
| 2298 | ) |
| 2299 | |
| 2300 | type event struct { |
| 2301 | what eventType |
| 2302 | instanceID string |
| 2303 | instanceDesc InstanceDesc |
| 2304 | shardSize int |
| 2305 | expected []string |
| 2306 | } |
| 2307 | |
| 2308 | tests := map[string]struct { |
| 2309 | timeline []event |
| 2310 | }{ |
| 2311 | "single zone, shard size = 1, recently bootstrapped cluster": { |
| 2312 | timeline: []event{ |
| 2313 | {what: add, instanceID: "instance-1", instanceDesc: generateRingInstanceWithInfo("instance-1", "zone-a", []uint32{userToken(userID, "zone-a", 0) + 1}, now.Add(-time.Minute))}, |
| 2314 | {what: add, instanceID: "instance-2", instanceDesc: generateRingInstanceWithInfo("instance-2", "zone-a", []uint32{userToken(userID, "zone-a", 1) + 1}, now.Add(-time.Minute))}, |
| 2315 | {what: add, instanceID: "instance-3", instanceDesc: generateRingInstanceWithInfo("instance-3", "zone-a", []uint32{userToken(userID, "zone-a", 2) + 1}, now.Add(-time.Minute))}, |
| 2316 | {what: test, shardSize: 1, expected: []string{"instance-1", "instance-2", "instance-3"}}, |
| 2317 | }, |
| 2318 | }, |
| 2319 | "single zone, shard size = 1, instances scale up": { |
| 2320 | timeline: []event{ |
| 2321 | {what: add, instanceID: "instance-1", instanceDesc: generateRingInstanceWithInfo("instance-1", "zone-a", []uint32{userToken(userID, "zone-a", 0) + 3}, now.Add(-2*lookbackPeriod))}, |
| 2322 | {what: add, instanceID: "instance-2", instanceDesc: generateRingInstanceWithInfo("instance-2", "zone-a", []uint32{userToken(userID, "zone-a", 1) + 1}, now.Add(-2*lookbackPeriod))}, |
| 2323 | {what: add, instanceID: "instance-3", instanceDesc: generateRingInstanceWithInfo("instance-3", "zone-a", []uint32{userToken(userID, "zone-a", 2) + 1}, now.Add(-2*lookbackPeriod))}, |
| 2324 | {what: test, shardSize: 1, expected: []string{"instance-1"}}, |
| 2325 | {what: add, instanceID: "instance-4", instanceDesc: generateRingInstanceWithInfo("instance-4", "zone-a", []uint32{userToken(userID, "zone-a", 0) + 2}, now.Add(-10*time.Minute))}, |
| 2326 | {what: test, shardSize: 1, expected: []string{"instance-4" /* lookback: */, "instance-1"}}, |
| 2327 | {what: add, instanceID: "instance-5", instanceDesc: generateRingInstanceWithInfo("instance-5", "zone-a", []uint32{userToken(userID, "zone-a", 0) + 1}, now.Add(-5*time.Minute))}, |
| 2328 | {what: test, shardSize: 1, expected: []string{"instance-5" /* lookback: */, "instance-4", "instance-1"}}, |
| 2329 | }, |
| 2330 | }, |
| 2331 | "single zone, shard size = 1, instances scale down": { |
| 2332 | timeline: []event{ |
| 2333 | {what: add, instanceID: "instance-1", instanceDesc: generateRingInstanceWithInfo("instance-1", "zone-a", []uint32{userToken(userID, "zone-a", 0) + 1}, now.Add(-2*lookbackPeriod))}, |
| 2334 | {what: add, instanceID: "instance-2", instanceDesc: generateRingInstanceWithInfo("instance-2", "zone-a", []uint32{userToken(userID, "zone-a", 1) + 1}, now.Add(-2*lookbackPeriod))}, |
| 2335 | {what: add, instanceID: "instance-3", instanceDesc: generateRingInstanceWithInfo("instance-3", "zone-a", []uint32{userToken(userID, "zone-a", 2) + 1}, now.Add(-2*lookbackPeriod))}, |
| 2336 | {what: test, shardSize: 1, expected: []string{"instance-1"}}, |
| 2337 | {what: remove, instanceID: "instance-3"}, |
| 2338 | {what: test, shardSize: 1, expected: []string{"instance-1"}}, |
| 2339 | {what: remove, instanceID: "instance-1"}, |
| 2340 | {what: test, shardSize: 1, expected: []string{"instance-2"}}, |
| 2341 | }, |
nothing calls this directly
no test coverage detected