(t *testing.T)
| 619 | } |
| 620 | |
| 621 | func TestRing_Get_ZoneAwareness(t *testing.T) { |
| 622 | // Number of tests to run. |
| 623 | const testCount = 10000 |
| 624 | |
| 625 | tests := map[string]struct { |
| 626 | numInstances int |
| 627 | numZones int |
| 628 | replicationFactor int |
| 629 | zoneAwarenessEnabled bool |
| 630 | expectedErr string |
| 631 | expectedInstances int |
| 632 | }{ |
| 633 | "should succeed if there are enough instances per zone on RF = 3": { |
| 634 | numInstances: 16, |
| 635 | numZones: 3, |
| 636 | replicationFactor: 3, |
| 637 | zoneAwarenessEnabled: true, |
| 638 | expectedInstances: 3, |
| 639 | }, |
| 640 | "should fail if there are instances in 1 zone only on RF = 3": { |
| 641 | numInstances: 16, |
| 642 | numZones: 1, |
| 643 | replicationFactor: 3, |
| 644 | zoneAwarenessEnabled: true, |
| 645 | expectedErr: "at least 2 live replicas required across different availability zones, could only find 1", |
| 646 | }, |
| 647 | "should succeed if there are instances in 2 zones on RF = 3": { |
| 648 | numInstances: 16, |
| 649 | numZones: 2, |
| 650 | replicationFactor: 3, |
| 651 | zoneAwarenessEnabled: true, |
| 652 | expectedInstances: 2, |
| 653 | }, |
| 654 | "should succeed if there are instances in 1 zone only on RF = 3 but zone-awareness is disabled": { |
| 655 | numInstances: 16, |
| 656 | numZones: 1, |
| 657 | replicationFactor: 3, |
| 658 | zoneAwarenessEnabled: false, |
| 659 | expectedInstances: 3, |
| 660 | }, |
| 661 | } |
| 662 | |
| 663 | for testName, testData := range tests { |
| 664 | t.Run(testName, func(t *testing.T) { |
| 665 | gen := initTokenGenerator(t) |
| 666 | |
| 667 | // Add instances to the ring. |
| 668 | r := NewDesc() |
| 669 | var prevTokens []uint32 |
| 670 | for i := 0; i < testData.numInstances; i++ { |
| 671 | name := fmt.Sprintf("ing%v", i) |
| 672 | ingTokens := gen.GenerateTokens(128, prevTokens) |
| 673 | |
| 674 | r.AddIngester(name, fmt.Sprintf("127.0.0.%d", i), fmt.Sprintf("zone-%v", i%testData.numZones), ingTokens, ACTIVE, time.Now(), false, time.Time{}, nil) |
| 675 | |
| 676 | prevTokens = append(prevTokens, ingTokens...) |
| 677 | } |
| 678 |
nothing calls this directly
no test coverage detected