multi_node_kill_all_and_recovery_test.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. // Create a five nodes
  9. // Kill all the nodes and restart
  10. func TestMultiNodeKillAllAndRecovery(t *testing.T) {
  11. procAttr := new(os.ProcAttr)
  12. procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
  13. stop := make(chan bool)
  14. leaderChan := make(chan string, 1)
  15. all := make(chan bool, 1)
  16. clusterSize := 5
  17. argGroup, etcds, err := CreateCluster(clusterSize, procAttr, false)
  18. defer DestroyCluster(etcds)
  19. if err != nil {
  20. t.Fatal("cannot create cluster")
  21. }
  22. c := etcd.NewClient(nil)
  23. go Monitor(clusterSize, clusterSize, leaderChan, all, stop)
  24. <-all
  25. <-leaderChan
  26. stop <- true
  27. c.SyncCluster()
  28. // send 10 commands
  29. for i := 0; i < 10; i++ {
  30. // Test Set
  31. _, err := c.Set("foo", "bar", 0)
  32. if err != nil {
  33. panic(err)
  34. }
  35. }
  36. time.Sleep(time.Second)
  37. // kill all
  38. DestroyCluster(etcds)
  39. time.Sleep(time.Second)
  40. stop = make(chan bool)
  41. leaderChan = make(chan string, 1)
  42. all = make(chan bool, 1)
  43. time.Sleep(time.Second)
  44. for i := 0; i < clusterSize; i++ {
  45. etcds[i], err = os.StartProcess(EtcdBinPath, argGroup[i], procAttr)
  46. }
  47. go Monitor(clusterSize, 1, leaderChan, all, stop)
  48. <-all
  49. <-leaderChan
  50. result, err := c.Set("foo", "bar", 0)
  51. if err != nil {
  52. t.Fatalf("Recovery error: %s", err)
  53. }
  54. if result.Node.ModifiedIndex != 16 {
  55. t.Fatalf("recovery failed! [%d/16]", result.Node.ModifiedIndex)
  56. }
  57. }
  58. // TestTLSMultiNodeKillAllAndRecovery create a five nodes
  59. // then kill all the nodes and restart
  60. func TestTLSMultiNodeKillAllAndRecovery(t *testing.T) {
  61. t.Skip("awaiting fix")
  62. procAttr := new(os.ProcAttr)
  63. procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
  64. stop := make(chan bool)
  65. leaderChan := make(chan string, 1)
  66. all := make(chan bool, 1)
  67. clusterSize := 5
  68. argGroup, etcds, err := CreateCluster(clusterSize, procAttr, true)
  69. defer DestroyCluster(etcds)
  70. if err != nil {
  71. t.Fatal("cannot create cluster")
  72. }
  73. c := etcd.NewClient(nil)
  74. go Monitor(clusterSize, clusterSize, leaderChan, all, stop)
  75. <-all
  76. <-leaderChan
  77. stop <- true
  78. c.SyncCluster()
  79. // send 10 commands
  80. for i := 0; i < 10; i++ {
  81. // Test Set
  82. _, err := c.Set("foo", "bar", 0)
  83. if err != nil {
  84. panic(err)
  85. }
  86. }
  87. time.Sleep(time.Second)
  88. // kill all
  89. DestroyCluster(etcds)
  90. time.Sleep(time.Second)
  91. stop = make(chan bool)
  92. leaderChan = make(chan string, 1)
  93. all = make(chan bool, 1)
  94. time.Sleep(time.Second)
  95. for i := 0; i < clusterSize; i++ {
  96. etcds[i], err = os.StartProcess(EtcdBinPath, argGroup[i], procAttr)
  97. }
  98. go Monitor(clusterSize, 1, leaderChan, all, stop)
  99. <-all
  100. <-leaderChan
  101. result, err := c.Set("foo", "bar", 0)
  102. if err != nil {
  103. t.Fatalf("Recovery error: %s", err)
  104. }
  105. if result.Node.ModifiedIndex != 16 {
  106. t.Fatalf("recovery failed! [%d/16]", result.Node.ModifiedIndex)
  107. }
  108. }