(t *testing.T)
| 2377 | } |
| 2378 | |
| 2379 | func TestRing_ShuffleShardWithLookback(t *testing.T) { |
| 2380 | type eventType int |
| 2381 | |
| 2382 | const ( |
| 2383 | add eventType = iota |
| 2384 | remove |
| 2385 | test |
| 2386 | |
| 2387 | lookbackPeriod = time.Hour |
| 2388 | userID = "user-1" |
| 2389 | ) |
| 2390 | |
| 2391 | now := time.Now().Truncate(time.Second) |
| 2392 | |
| 2393 | type event struct { |
| 2394 | what eventType |
| 2395 | instanceID string |
| 2396 | instanceDesc InstanceDesc |
| 2397 | shardSize int |
| 2398 | expected []string |
| 2399 | readOnly bool |
| 2400 | readOnlyTime time.Time |
| 2401 | } |
| 2402 | |
| 2403 | tests := map[string]struct { |
| 2404 | timeline []event |
| 2405 | }{ |
| 2406 | "single zone, shard size = 1, recently bootstrapped cluster": { |
| 2407 | timeline: []event{ |
| 2408 | {what: add, instanceID: "instance-1", instanceDesc: generateRingInstanceWithInfo("instance-1", "zone-a", []uint32{userToken(userID, "zone-a", 0) + 1}, now.Add(-time.Minute))}, |
| 2409 | {what: add, instanceID: "instance-2", instanceDesc: generateRingInstanceWithInfo("instance-2", "zone-a", []uint32{userToken(userID, "zone-a", 1) + 1}, now.Add(-time.Minute))}, |
| 2410 | {what: add, instanceID: "instance-3", instanceDesc: generateRingInstanceWithInfo("instance-3", "zone-a", []uint32{userToken(userID, "zone-a", 2) + 1}, now.Add(-time.Minute))}, |
| 2411 | {what: test, shardSize: 1, expected: []string{"instance-1", "instance-2", "instance-3"}}, |
| 2412 | }, |
| 2413 | }, |
| 2414 | "single zone, shard size = 0, recently bootstrapped cluster": { |
| 2415 | timeline: []event{ |
| 2416 | {what: add, instanceID: "instance-1", instanceDesc: generateRingInstanceWithInfo("instance-1", "zone-a", []uint32{userToken(userID, "zone-a", 0) + 1}, now.Add(-time.Minute))}, |
| 2417 | {what: add, instanceID: "instance-2", instanceDesc: generateRingInstanceWithInfo("instance-2", "zone-a", []uint32{userToken(userID, "zone-a", 1) + 1}, now.Add(-time.Minute))}, |
| 2418 | {what: add, instanceID: "instance-3", instanceDesc: generateRingInstanceWithInfo("instance-3", "zone-a", []uint32{userToken(userID, "zone-a", 2) + 1}, now.Add(-time.Minute))}, |
| 2419 | {what: test, shardSize: 0, expected: []string{"instance-1", "instance-2", "instance-3"}}, |
| 2420 | }, |
| 2421 | }, |
| 2422 | "single zone, shard size = 1, instances scale up": { |
| 2423 | timeline: []event{ |
| 2424 | {what: add, instanceID: "instance-1", instanceDesc: generateRingInstanceWithInfo("instance-1", "zone-a", []uint32{userToken(userID, "zone-a", 0) + 3}, now.Add(-2*lookbackPeriod))}, |
| 2425 | {what: add, instanceID: "instance-2", instanceDesc: generateRingInstanceWithInfo("instance-2", "zone-a", []uint32{userToken(userID, "zone-a", 1) + 1}, now.Add(-2*lookbackPeriod))}, |
| 2426 | {what: add, instanceID: "instance-3", instanceDesc: generateRingInstanceWithInfo("instance-3", "zone-a", []uint32{userToken(userID, "zone-a", 2) + 1}, now.Add(-2*lookbackPeriod))}, |
| 2427 | {what: test, shardSize: 1, expected: []string{"instance-1"}}, |
| 2428 | {what: add, instanceID: "instance-4", instanceDesc: generateRingInstanceWithInfo("instance-4", "zone-a", []uint32{userToken(userID, "zone-a", 0) + 2}, now.Add(-10*time.Minute))}, |
| 2429 | {what: test, shardSize: 1, expected: []string{"instance-4" /* lookback: */, "instance-1"}}, |
| 2430 | {what: add, instanceID: "instance-5", instanceDesc: generateRingInstanceWithInfo("instance-5", "zone-a", []uint32{userToken(userID, "zone-a", 0) + 1}, now.Add(-5*time.Minute))}, |
| 2431 | {what: test, shardSize: 1, expected: []string{"instance-5" /* lookback: */, "instance-4", "instance-1"}}, |
| 2432 | }, |
| 2433 | }, |
| 2434 | "single zone, shard size = 1, instances scale down": { |
| 2435 | timeline: []event{ |
| 2436 | {what: add, instanceID: "instance-1", instanceDesc: generateRingInstanceWithInfo("instance-1", "zone-a", []uint32{userToken(userID, "zone-a", 0) + 1}, now.Add(-2*lookbackPeriod))}, |
nothing calls this directly
no test coverage detected