github.com/matm/etcd@v0.3.1-0.20140328024009-5b4a473f1453/tests/functional/multi_node_kill_all_and_recovery_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 // Create a five nodes 12 // Kill all the nodes and restart 13 func TestMultiNodeKillAllAndRecovery(t *testing.T) { 14 procAttr := new(os.ProcAttr) 15 procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr} 16 17 stop := make(chan bool) 18 leaderChan := make(chan string, 1) 19 all := make(chan bool, 1) 20 21 clusterSize := 5 22 argGroup, etcds, err := CreateCluster(clusterSize, procAttr, false) 23 defer DestroyCluster(etcds) 24 25 if err != nil { 26 t.Fatal("cannot create cluster") 27 } 28 29 c := etcd.NewClient(nil) 30 31 go Monitor(clusterSize, clusterSize, leaderChan, all, stop) 32 <-all 33 <-leaderChan 34 stop <- true 35 36 c.SyncCluster() 37 38 // send 10 commands 39 for i := 0; i < 10; i++ { 40 // Test Set 41 _, err := c.Set("foo", "bar", 0) 42 if err != nil { 43 panic(err) 44 } 45 } 46 47 time.Sleep(time.Second) 48 49 // kill all 50 DestroyCluster(etcds) 51 52 time.Sleep(time.Second) 53 54 stop = make(chan bool) 55 leaderChan = make(chan string, 1) 56 all = make(chan bool, 1) 57 58 time.Sleep(time.Second) 59 60 for i := 0; i < clusterSize; i++ { 61 etcds[i], err = os.StartProcess(EtcdBinPath, argGroup[i], procAttr) 62 } 63 64 go Monitor(clusterSize, 1, leaderChan, all, stop) 65 66 <-all 67 <-leaderChan 68 69 result, err := c.Set("foo", "bar", 0) 70 71 if err != nil { 72 t.Fatalf("Recovery error: %s", err) 73 } 74 75 if result.Node.ModifiedIndex != 16 { 76 t.Fatalf("recovery failed! [%d/16]", result.Node.ModifiedIndex) 77 } 78 } 79 80 // TestTLSMultiNodeKillAllAndRecovery create a five nodes 81 // then kill all the nodes and restart 82 func TestTLSMultiNodeKillAllAndRecovery(t *testing.T) { 83 procAttr := new(os.ProcAttr) 84 procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr} 85 86 stop := make(chan bool) 87 leaderChan := make(chan string, 1) 88 all := make(chan bool, 1) 89 90 clusterSize := 5 91 argGroup, etcds, err := CreateCluster(clusterSize, procAttr, true) 92 defer DestroyCluster(etcds) 93 94 if err != nil { 95 t.Fatal("cannot create cluster") 96 } 97 98 c := etcd.NewClient(nil) 99 100 go Monitor(clusterSize, clusterSize, leaderChan, all, stop) 101 <-all 102 <-leaderChan 103 stop <- true 104 105 c.SyncCluster() 106 107 // send 10 commands 108 for i := 0; i < 10; i++ { 109 // Test Set 110 _, err := c.Set("foo", "bar", 0) 111 if err != nil { 112 panic(err) 113 } 114 } 115 116 time.Sleep(time.Second) 117 118 // kill all 119 DestroyCluster(etcds) 120 121 time.Sleep(time.Second) 122 123 stop = make(chan bool) 124 leaderChan = make(chan string, 1) 125 all = make(chan bool, 1) 126 127 time.Sleep(time.Second) 128 129 for i := 0; i < clusterSize; i++ { 130 etcds[i], err = os.StartProcess(EtcdBinPath, argGroup[i], procAttr) 131 } 132 133 go Monitor(clusterSize, 1, leaderChan, all, stop) 134 135 <-all 136 <-leaderChan 137 138 result, err := c.Set("foo", "bar", 0) 139 140 if err != nil { 141 t.Fatalf("Recovery error: %s", err) 142 } 143 144 if result.Node.ModifiedIndex != 16 { 145 t.Fatalf("recovery failed! [%d/16]", result.Node.ModifiedIndex) 146 } 147 }