Skip to content

Commit

Permalink
storage: improve TestSystemZoneConfigs
Browse files Browse the repository at this point in the history
The failure mode in #40980 didn't give out any actionable information.
It now prints the mismatching descriptors.

Release justification: testing-only improvement.

Release note: None
  • Loading branch information
tbg committed Sep 26, 2019
1 parent 9dd1564 commit 03dfb39
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions pkg/storage/client_replica_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1719,28 +1719,24 @@ func TestSystemZoneConfigs(t *testing.T) {
expectedSystemRanges, systemNumReplicas, expectedUserRanges, userNumReplicas, expectedReplicas)

waitForReplicas := func() error {
var conflictingID roachpb.RangeID
replicas := make(map[roachpb.RangeID]int)
replicas := make(map[roachpb.RangeID]roachpb.RangeDescriptor)
for _, s := range tc.Servers {
if err := storage.IterateRangeDescriptors(ctx, s.Engines()[0], func(desc roachpb.RangeDescriptor) (bool, error) {
if existing, ok := replicas[desc.RangeID]; ok && existing != len(desc.InternalReplicas) {
conflictingID = desc.RangeID
if existing, ok := replicas[desc.RangeID]; ok && !existing.Equal(desc) {
return false, fmt.Errorf("mismatch between\n%s\n%s", &existing, &desc)
}
replicas[desc.RangeID] = len(desc.InternalReplicas)
replicas[desc.RangeID] = desc
return false, nil
}); err != nil {
return err
}
}
if conflictingID != 0 {
return fmt.Errorf("not all replicas agree on the range descriptor for r%d", conflictingID)
}
var totalReplicas int
for _, count := range replicas {
totalReplicas += count
for _, desc := range replicas {
totalReplicas += len(desc.Replicas().Voters())
}
if totalReplicas != expectedReplicas {
return fmt.Errorf("got %d replicas, want %d; details: %+v", totalReplicas, expectedReplicas, replicas)
return fmt.Errorf("got %d voters, want %d; details: %+v", totalReplicas, expectedReplicas, replicas)
}
return nil
}
Expand Down

0 comments on commit 03dfb39

Please sign in to comment.