Skip to content

Commit

Permalink
add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
nolouch committed Sep 13, 2018
1 parent 87ca397 commit 235e0f1
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions integration/network_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
package integration

import (
"context"
"fmt"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -139,6 +141,43 @@ func TestNetworkPartition4Members(t *testing.T) {
clusterMustProgress(t, clus.Members)
}

func TestNetworkPartitionFastFail(t *testing.T) {
defer testutil.AfterTest(t)

clus := NewClusterV3(t, &ClusterConfig{Size: 5})
defer clus.Terminate(t)

leadIndex := clus.WaitLeader(t)

// majority: leader, follower, follower / minority: follower, follower
majority := []int{leadIndex, (leadIndex + 1) % 5, (leadIndex + 2) % 5}
minority := []int{(leadIndex + 3) % 5, (leadIndex + 4) % 5}

majorityMembers := getMembersByIndexSlice(clus.cluster, majority)
minorityMembers := getMembersByIndexSlice(clus.cluster, minority)

cliIndex := minority[0]
cli := clus.Client(cliIndex)
timeout := 20 * time.Second
ctx, cancel := context.WithTimeout(context.Background(), timeout)
_, err := cli.Put(ctx, "foo", "bar")
cancel()
if err != nil {
t.Fatalf("put request with client %d, get error: %v", cliIndex, err)
}
// network partition (bi-directional)
injectPartition(t, majorityMembers, minorityMembers)

// minority leader must be lost
clus.waitNoLeader(minorityMembers)
ctx, cancel = context.WithTimeout(context.Background(), timeout)
_, err = cli.Get(ctx, "foo")
cancel()
if !strings.Contains(err.Error(), "raft read index dropped") {
t.Fatalf("expect dropped read index error, but get %s", err)
}
}

func getMembersByIndexSlice(clus *cluster, idxs []int) []*member {
ms := make([]*member, len(idxs))
for i, idx := range idxs {
Expand Down

0 comments on commit 235e0f1

Please sign in to comment.