Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robskillington committed Nov 18, 2020
1 parent 5b5d75a commit 8d8f08f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/cluster/placement/placement.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ func validate(p Placement) error {
instancesLeavingShardsWithMatchingInitShards[sourceID] = matches
}

match := matches[s.ID()]
if match != "" {
match, ok := matches[s.ID()]
if ok {
return fmt.Errorf(
"instance %s has initializing shard %d with "+
"source ID %s but leaving instance has shard already matched by %s",
Expand Down
18 changes: 10 additions & 8 deletions src/cluster/placement/placement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func TestMismatchShards(t *testing.T) {

// mismatch shards
p := NewPlacement().SetInstances([]Instance{i1, i2}).SetShards([]uint32{1, 2, 3}).SetReplicaFactor(1)
assert.Error(t, Validate(p))
require.Error(t, Validate(p))
}

func TestNonSharded(t *testing.T) {
Expand All @@ -156,8 +156,8 @@ func TestNonSharded(t *testing.T) {
func TestValidateMirrorButNotSharded(t *testing.T) {
p := NewPlacement().SetIsMirrored(true)
err := Validate(p)
assert.Error(t, err)
assert.Equal(t, errMirrorNotSharded, err)
require.Error(t, err)
assert.Equal(t, errMirrorNotSharded.Error(), err.Error())
}

func TestValidateMissingShard(t *testing.T) {
Expand All @@ -171,7 +171,7 @@ func TestValidateMissingShard(t *testing.T) {
ids := []uint32{1, 2}
p := NewPlacement().SetInstances([]Instance{i1, i2}).SetShards(ids).SetReplicaFactor(2).SetIsSharded(true)
err := Validate(p)
assert.Error(t, err)
require.Error(t, err)
assert.Equal(t, "invalid placement, the total available shards in the placement is 3, expecting 4", err.Error())
}

Expand All @@ -190,8 +190,9 @@ func TestValidateUnexpectedShard(t *testing.T) {
SetReplicaFactor(2).
SetIsSharded(true)

assert.Error(t, Validate(p))
assert.Equal(t, errUnexpectedShards, Validate(p))
err := Validate(p)
require.Error(t, err)
assert.Equal(t, errUnexpectedShards.Error(), err.Error())
}

func TestValidateDuplicatedShards(t *testing.T) {
Expand All @@ -209,8 +210,9 @@ func TestValidateDuplicatedShards(t *testing.T) {
SetInstances([]Instance{i1, i2}).
SetShards([]uint32{2, 3, 4, 4, 5, 6}).
SetReplicaFactor(1)
assert.Error(t, Validate(p))
assert.Equal(t, errDuplicatedShards, Validate(p))
err := Validate(p)
require.Error(t, err)
assert.Equal(t, errDuplicatedShards.Error(), err.Error())
}

func TestValidateWrongReplicaForSomeShards(t *testing.T) {
Expand Down

0 comments on commit 8d8f08f

Please sign in to comment.