simple_multi_node_test.go 1.3 KB

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