github.com/macb/etcd@v0.3.1-0.20140227003422-a60481c6b1a0/tests/functional/simple_multi_node_test.go (about) 1 package test 2 3 import ( 4 "os" 5 "testing" 6 "time" 7 8 "github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd" 9 ) 10 11 func TestSimpleMultiNode(t *testing.T) { 12 templateTestSimpleMultiNode(t, false) 13 } 14 15 func TestSimpleMultiNodeTls(t *testing.T) { 16 templateTestSimpleMultiNode(t, true) 17 } 18 19 // Create a three nodes and try to set value 20 func templateTestSimpleMultiNode(t *testing.T, tls bool) { 21 procAttr := new(os.ProcAttr) 22 procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr} 23 24 clusterSize := 3 25 26 _, etcds, err := CreateCluster(clusterSize, procAttr, tls) 27 28 if err != nil { 29 t.Fatalf("cannot create cluster: %v", err) 30 } 31 32 defer DestroyCluster(etcds) 33 34 time.Sleep(time.Second) 35 36 c := etcd.NewClient(nil) 37 38 if c.SyncCluster() == false { 39 t.Fatal("Cannot sync cluster!") 40 } 41 42 // Test Set 43 result, err := c.Set("foo", "bar", 100) 44 if err != nil { 45 t.Fatal(err) 46 } 47 48 node := result.Node 49 if node.Key != "/foo" || node.Value != "bar" || node.TTL < 95 { 50 t.Fatalf("Set 1 failed with %s %s %v", node.Key, node.Value, node.TTL) 51 } 52 53 time.Sleep(time.Second) 54 55 result, err = c.Set("foo", "bar", 100) 56 if err != nil { 57 t.Fatal(err) 58 } 59 60 node = result.Node 61 if node.Key != "/foo" || node.Value != "bar" || node.TTL < 95 { 62 t.Fatalf("Set 2 failed with %s %s %v", node.Key, node.Value, node.TTL) 63 } 64 65 }