Skip to content

Commit

Permalink
Use require package for test assertions
Browse files Browse the repository at this point in the history
Signed-off-by: Filip Petkovski <[email protected]>
  • Loading branch information
fpetkovski committed Jun 14, 2022
1 parent d2ed2b3 commit 580ac6e
Showing 1 changed file with 13 additions and 33 deletions.
46 changes: 13 additions & 33 deletions pkg/receive/hashring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"fmt"
"testing"

"github.com/stretchr/testify/require"

"github.com/prometheus/prometheus/model/labels"

"github.com/thanos-io/thanos/pkg/store/labelpb"
Expand Down Expand Up @@ -230,9 +232,7 @@ func TestConsistentHashringGet(t *testing.T) {
t.Error(err)
}

if result != test.expectedNode {
t.Fatalf("invalid result: got %s, want %s", result, test.expectedNode)
}
require.Equal(t, test.expectedNode, result)
})
}
}
Expand All @@ -242,26 +242,18 @@ func TestConsistentHashringConsistency(t *testing.T) {

ringA := []string{"node-1", "node-2", "node-3"}
a1, err := assignSeries(series, ringA)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

ringB := []string{"node-1", "node-2", "node-3"}
a2, err := assignSeries(series, ringB)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

for node, ts := range a1 {
if len(a2[node]) != len(ts) {
t.Fatalf("node %s has an inconsistent number of series", node)
}
require.Len(t, a2[node], len(ts), "node %s has an inconsistent number of series", node)
}

for node, ts := range a2 {
if len(a1[node]) != len(ts) {
t.Fatalf("node %s has an inconsistent number of series", node)
}
require.Len(t, a1[node], len(ts), "node %s has an inconsistent number of series", node)
}
}

Expand All @@ -270,23 +262,17 @@ func TestConsistentHashringIncreaseAtEnd(t *testing.T) {

initialRing := []string{"node-1", "node-2", "node-3"}
initialAssignments, err := assignSeries(series, initialRing)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

resizedRing := []string{"node-1", "node-2", "node-3", "node-4", "node-5"}
reassignments, err := assignSeries(series, resizedRing)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

// Assert that the initial nodes have no new keys after increasing the ring size
for _, node := range initialRing {
for _, ts := range reassignments[node] {
foundInInitialAssignment := findSeries(initialAssignments, node, ts)
if !foundInInitialAssignment {
t.Fatalf("node %s contains new series after resizing: %s", node, ts)
}
require.True(t, foundInInitialAssignment, "node %s contains new series after resizing", node)
}
}
}
Expand All @@ -296,23 +282,17 @@ func TestConsistentHashringIncreaseInMiddle(t *testing.T) {

initialRing := []string{"node-1", "node-3"}
initialAssignments, err := assignSeries(series, initialRing)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

resizedRing := []string{"node-1", "node-2", "node-3"}
reassignments, err := assignSeries(series, resizedRing)
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)

// Assert that the initial nodes have no new keys after increasing the ring size
for _, node := range initialRing {
for _, ts := range reassignments[node] {
foundInInitialAssignment := findSeries(initialAssignments, node, ts)
if !foundInInitialAssignment {
t.Fatalf("node %s contains new series after resizing", node)
}
require.True(t, foundInInitialAssignment, "node %s contains new series after resizing", node)
}
}
}
Expand Down

0 comments on commit 580ac6e

Please sign in to comment.