Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions pkg/ring/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,3 +600,81 @@ func TestDesc_FindDifference(t *testing.T) {
})
}
}

func Test_resolveConflicts(t *testing.T) {
tests := []struct {
name string
args map[string]InstanceDesc
want map[string]InstanceDesc
}{
{
name: "Empty input",
args: map[string]InstanceDesc{},
want: map[string]InstanceDesc{},
},
{
name: "No conflicts",
args: map[string]InstanceDesc{
"ing1": {State: ACTIVE, Tokens: []uint32{1, 2, 3}},
"ing2": {State: ACTIVE, Tokens: []uint32{4, 5, 6}},
},
want: map[string]InstanceDesc{
"ing1": {State: ACTIVE, Tokens: []uint32{1, 2, 3}},
"ing2": {State: ACTIVE, Tokens: []uint32{4, 5, 6}},
},
},
{
name: "Conflict resolution with LEFT state",
args: map[string]InstanceDesc{
"ing1": {State: ACTIVE, Tokens: []uint32{1, 2, 3}},
"ing2": {State: LEFT, Tokens: []uint32{1, 2, 3, 4}},
},
want: map[string]InstanceDesc{
"ing1": {State: ACTIVE, Tokens: []uint32{1, 2, 3}},
"ing2": {State: LEFT, Tokens: nil},
},
},
{
name: "Conflict resolution with LEAVING state",
args: map[string]InstanceDesc{
"ing1": {State: LEAVING, Tokens: []uint32{1, 2, 3}},
"ing2": {State: PENDING, Tokens: []uint32{1, 2, 3, 4}},
},
want: map[string]InstanceDesc{
"ing1": {State: LEAVING, Tokens: nil},
"ing2": {State: PENDING, Tokens: []uint32{1, 2, 3, 4}},
},
},
{
name: "Conflict resolution with JOINING state",
args: map[string]InstanceDesc{
"ing1": {State: ACTIVE, Tokens: []uint32{1, 2, 3}},
"ing2": {State: JOINING, Tokens: []uint32{1, 2, 3, 4}},
},
want: map[string]InstanceDesc{
"ing1": {State: ACTIVE, Tokens: []uint32{1, 2, 3}},
"ing2": {State: JOINING, Tokens: []uint32{4}},
},
},
{
name: "Conflict resolution with same state",
args: map[string]InstanceDesc{
"ing1": {State: ACTIVE, Tokens: []uint32{1, 2, 3}},
"ing2": {State: ACTIVE, Tokens: []uint32{1, 2, 3, 4}},
},
want: map[string]InstanceDesc{
"ing1": {State: ACTIVE, Tokens: []uint32{1, 2, 3}},
"ing2": {State: ACTIVE, Tokens: []uint32{4}},
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
resolveConflicts(tt.args)
for key, actualInstance := range tt.args {
assert.Equal(t, actualInstance, tt.want[key])
}
})
}
}