Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Heckel committed Jul 14, 2021
1 parent c81e97a commit 926048c
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions go/inst/instance_topology_dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package inst

import (
"github.com/openark/golib/log"
test "github.com/openark/golib/tests"
"github.com/openark/orchestrator/go/config"
"testing"
)
Expand Down Expand Up @@ -109,3 +110,51 @@ func TestClassifyAndPrioritizeReplicas_NonReplicatingReplica(t *testing.T) {
expectInstancesMatch(t, asyncReplicas, []*Instance{})
expectInstancesMatch(t, excludedReplicas, []*Instance{})
}

func TestDetermineSemiSyncReplicaActionsForExactTopology_EnableSomeDisableSome(t *testing.T) {
master := &Instance{SemiSyncMasterWaitForReplicaCount: 2}
replica1 := &Instance{SemiSyncReplicaEnabled: true}
replica2 := &Instance{SemiSyncReplicaEnabled: false}
replica3 := &Instance{SemiSyncReplicaEnabled: true}
replica4 := &Instance{SemiSyncReplicaEnabled: false}
replica5 := &Instance{SemiSyncReplicaEnabled: true}
possibleSemiSyncReplicas := []*Instance{replica1, replica2, replica3, replica4}
asyncReplicas := []*Instance{replica5}
actions := determineSemiSyncReplicaActionsForExactTopology(master, possibleSemiSyncReplicas, asyncReplicas)
test.S(t).ExpectTrue(len(actions) == 3)
test.S(t).ExpectTrue(actions[replica2])
test.S(t).ExpectFalse(actions[replica3])
test.S(t).ExpectTrue(actions[replica5])
}

func TestDetermineSemiSyncReplicaActionsForExactTopology_NoActions(t *testing.T) {
master := &Instance{SemiSyncMasterWaitForReplicaCount: 1}
replica1 := &Instance{SemiSyncReplicaEnabled: true}
replica2 := &Instance{SemiSyncReplicaEnabled: false}
replica3 := &Instance{SemiSyncReplicaEnabled: false}
possibleSemiSyncReplicas := []*Instance{replica1, replica2, replica3}
asyncReplicas := []*Instance{}
actions := determineSemiSyncReplicaActionsForExactTopology(master, possibleSemiSyncReplicas, asyncReplicas)
test.S(t).ExpectTrue(len(actions) == 0)
}

func TestDetermineSemiSyncReplicaActionsForEnoughTopology_MoreThanWaitCountNoActions(t *testing.T) {
master := &Instance{SemiSyncMasterWaitForReplicaCount: 1}
replica1 := &Instance{SemiSyncReplicaEnabled: true}
replica2 := &Instance{SemiSyncReplicaEnabled: true}
replica3 := &Instance{SemiSyncReplicaEnabled: true}
possibleSemiSyncReplicas := []*Instance{replica1, replica2, replica3}
actions := determineSemiSyncReplicaActionsForEnoughTopology(master, possibleSemiSyncReplicas)
test.S(t).ExpectTrue(len(actions) == 0)
}

func TestDetermineSemiSyncReplicaActionsForEnoughTopology_LessThanWaitCountEnableOne(t *testing.T) {
master := &Instance{SemiSyncMasterWaitForReplicaCount: 2}
replica1 := &Instance{SemiSyncReplicaEnabled: false}
replica2 := &Instance{SemiSyncReplicaEnabled: true}
replica3 := &Instance{SemiSyncReplicaEnabled: false}
possibleSemiSyncReplicas := []*Instance{replica1, replica2, replica3}
actions := determineSemiSyncReplicaActionsForEnoughTopology(master, possibleSemiSyncReplicas)
test.S(t).ExpectTrue(len(actions) == 1)
test.S(t).ExpectTrue(actions[replica1])
}

0 comments on commit 926048c

Please sign in to comment.