-
Notifications
You must be signed in to change notification settings - Fork 5
/
crud_int_test.go
93 lines (77 loc) · 2.26 KB
/
crud_int_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package gocbcorex_test
import (
"context"
"testing"
"time"
"github.com/couchbase/gocbcorex"
"github.com/couchbase/gocbcorex/testutilsint"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
const NUM_REPLICAS = 2
func TestGetAllReplicasDino(t *testing.T) {
testutilsint.SkipIfNoDinoCluster(t)
opts := CreateDefaultAgentOptions()
agent, err := gocbcorex.CreateAgent(context.Background(), opts)
defer func() {
err := agent.Close()
require.NoError(t, err)
}()
require.NoError(t, err)
docKey := uuid.NewString()
upsertRes, err := agent.Upsert(context.Background(), &gocbcorex.UpsertOptions{
Key: []byte(docKey),
ScopeName: "",
CollectionName: "",
Value: []byte(`{"foo": "bar"}`),
})
require.NoError(t, err)
assert.NotZero(t, upsertRes.Cas)
require.Eventually(t, func() bool {
count := replicaCount(t, agent, docKey)
return count == NUM_REPLICAS+1
}, time.Second*15, time.Second*1)
nodes := testutilsint.GetTestNodes(t)
nonOrchestrators := nodes.Select(func(node *testutilsint.NodeTarget) bool {
return !node.IsOrchestrator
})
blocked := 0
dino := testutilsint.StartDinoTesting(t, true)
for _, node := range nonOrchestrators {
dino.BlockAllTraffic(node.Hostname)
blocked += 1
require.Eventually(t, func() bool {
count := replicaCount(t, agent, docKey)
return count == NUM_REPLICAS+1-blocked
}, time.Second*30, time.Second*1)
}
for _, node := range nonOrchestrators {
dino.AllowTraffic(node.Hostname)
blocked -= 1
require.Eventually(t, func() bool {
count := replicaCount(t, agent, docKey)
return count == NUM_REPLICAS+1-blocked
}, time.Second*30, time.Second*1)
}
}
func replicaCount(t *testing.T, agent *gocbcorex.Agent, docKey string) int {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
stream, err := agent.GetAllReplicas(ctx, &gocbcorex.GetAllReplicasOptions{
Key: []byte(docKey),
BucketName: "default",
ScopeName: "",
CollectionName: "",
})
require.NoError(t, err)
result, err := stream.Next()
count := 0
for result != nil {
require.NoError(t, err)
require.Equal(t, result.Value, []byte(`{"foo": "bar"}`))
count += 1
result, err = stream.Next()
}
return count
}