Commit 9e3b6e18 authored by pfandzelter's avatar pfandzelter
Browse files

add tests for getreplica

parent b4fa62bf
Pipeline #33359 passed with stages
in 10 minutes and 58 seconds
......@@ -21,13 +21,12 @@ import (
const (
certBasePath = "../../tests/runner/certificates/"
etcdDir = ".default.etcd"
nodeID = fred.NodeID("X")
)
var f fred.Fred
func TestMain(m *testing.M) {
nodeID := "X"
log.Logger = log.Output(
zerolog.ConsoleWriter{
Out: os.Stderr,
......@@ -74,7 +73,7 @@ func TestMain(m *testing.M) {
<-e.Server.ReadyNotify()
n, err := etcdnase.NewNameService(nodeID, []string{"127.0.0.1:6000"}, certBasePath+"nodeA.crt", certBasePath+"nodeA.key", certBasePath+"ca.crt", true)
n, err := etcdnase.NewNameService(string(nodeID), []string{"127.0.0.1:6000"}, certBasePath+"nodeA.crt", certBasePath+"nodeA.key", certBasePath+"ca.crt", true)
if err != nil {
panic(err)
......@@ -88,7 +87,7 @@ func TestMain(m *testing.M) {
PeeringHostProxy: "",
ExternalHost: "127.0.0.1:9000",
ExternalHostProxy: "",
NodeID: nodeID,
NodeID: string(nodeID),
TriggerCert: certBasePath + "nodeA.crt",
TriggerKey: certBasePath + "nodeA.key",
TriggerCA: []string{certBasePath + "ca.crt"},
......@@ -426,6 +425,50 @@ func TestPermissions(t *testing.T) {
assert.Error(t, err)
}
func TestAllReplicas(t *testing.T) {
nodes, err := f.E.HandleGetAllReplica("user")
assert.NoError(t, err)
assert.Len(t, nodes, 1)
assert.Equal(t, nodeID, nodes[0].ID)
assert.Equal(t, "127.0.0.1:9000", nodes[0].Host)
}
func TestSingleReplica(t *testing.T) {
node, err := f.E.HandleGetReplica("user", fred.Node{ID: nodeID})
assert.NoError(t, err)
assert.Equal(t, nodeID, node.ID)
assert.Equal(t, "127.0.0.1:9000", node.Host)
_, err = f.E.HandleGetReplica("user", fred.Node{ID: "Y"})
assert.Error(t, err)
}
func TestKeygroupReplicas(t *testing.T) {
user := "user1"
var kg fred.KeygroupName = "replicakeygroup"
err := f.E.HandleCreateKeygroup(user, fred.Keygroup{
Name: kg,
Mutable: true,
Expiry: 0,
})
assert.NoError(t, err)
nodes, expiries, err := f.E.HandleGetKeygroupReplica(user, fred.Keygroup{Name: kg})
assert.NoError(t, err)
assert.Len(t, nodes, 1)
assert.Equal(t, nodeID, nodes[0].ID)
assert.Equal(t, "127.0.0.1:9000", nodes[0].Host)
assert.Len(t, expiries, 1)
assert.Equal(t, expiries[nodes[0].ID], 0)
}
func BenchmarkPut(b *testing.B) {
user := "user"
kg := "benchmarkPut"
......
......@@ -106,6 +106,25 @@ func (t *ReplicaSuite) RunTests() {
// NodeB is the only replica left
logNodeAction(t.c.nodeB, "Removing last member of a keygroup delete-test")
t.c.nodeB.DeleteKeygroupReplica("deletetest", t.c.nodeB.ID, true)
// checking "GetReplicas" and "GetKeygroupReplica"
logNodeAction(t.c.nodeB, "Testing GetReplica and GetKeygroupReplica")
_, host := t.c.nodeB.GetReplica(t.c.nodeA.ID, false)
if host != fmt.Sprintf("%s:%s", t.c.nodeA.Addr, t.c.nodeAhttpPort) {
logNodeFailure(t.c.nodeB, fmt.Sprintf("%s:%s", t.c.nodeA.Addr, t.c.nodeAhttpPort), host)
}
t.c.nodeB.CreateKeygroup("replicanodetest", true, 0, false)
t.c.nodeB.AddKeygroupReplica("replicanodetest", t.c.nodeA.ID, 10, false)
hosts := t.c.nodeA.GetKeygroupReplica("replicanodetest", false)
if len(hosts) != 2 {
logNodeFailure(t.c.nodeA, "2 hosts", fmt.Sprintf("%d host(s)", len(hosts)))
}
if expiry, ok := hosts[t.c.nodeA.ID]; !ok || expiry != 10 {
logNodeFailure(t.c.nodeA, "expiry of 10 for nodeA", "nodeA not in replica list or expiry wrong")
}
if expiry, ok := hosts[t.c.nodeB.ID]; !ok || expiry != 0 {
logNodeFailure(t.c.nodeA, "expiry of 0 for nodeB", "nodeB not in replica list or expiry wrong")
}
}
func NewReplicaSuite(c *Config) *ReplicaSuite {
......
......@@ -299,7 +299,7 @@ func (n *Node) GetAllReplica(expectError bool) map[string]string {
}
// GetReplica calls the GetReplica endpoint of the GRPC interface.
func (n *Node) GetReplica(nodeID string, expectError bool) string {
func (n *Node) GetReplica(nodeID string, expectError bool) (string, string) {
res, err := n.Client.GetReplica(context.Background(), &client.GetReplicaRequest{NodeId: nodeID})
if err != nil && !expectError {
......@@ -313,10 +313,10 @@ func (n *Node) GetReplica(nodeID string, expectError bool) string {
}
if res == nil {
return ""
return "", ""
}
return res.NodeId
return res.NodeId, res.Host
}
// PutItem calls the PutItem endpoint of the GRPC interface.
......
......@@ -2,7 +2,7 @@ version: "3.7"
services:
etcd:
image: quay.io/coreos/etcd:v3.4.10
image: gcr.io/etcd-development/etcd:v3.5.0
container_name: etcd-1
entrypoint: "etcd --name s-1 \
--data-dir /tmp/etcd/s-1 \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment