multi_node_kill_one_test.go 1014 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package test
  2. import (
  3. "fmt"
  4. "math/rand"
  5. "os"
  6. "testing"
  7. "time"
  8. "github.com/coreos/go-etcd/etcd"
  9. )
  10. // Create a five nodes
  11. // Randomly kill one of the node and keep on sending set command to the cluster
  12. func TestMultiNodeKillOne(t *testing.T) {
  13. procAttr := new(os.ProcAttr)
  14. procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
  15. clusterSize := 5
  16. argGroup, etcds, err := CreateCluster(clusterSize, procAttr, false)
  17. if err != nil {
  18. t.Fatal("cannot create cluster")
  19. }
  20. defer DestroyCluster(etcds)
  21. time.Sleep(2 * time.Second)
  22. c := etcd.NewClient(nil)
  23. c.SyncCluster()
  24. stop := make(chan bool)
  25. // Test Set
  26. go Set(stop)
  27. for i := 0; i < 10; i++ {
  28. num := rand.Int() % clusterSize
  29. fmt.Println("kill node", num+1)
  30. // kill
  31. etcds[num].Kill()
  32. etcds[num].Release()
  33. time.Sleep(time.Second)
  34. // restart
  35. etcds[num], err = os.StartProcess(EtcdBinPath, argGroup[num], procAttr)
  36. if err != nil {
  37. panic(err)
  38. }
  39. time.Sleep(time.Second)
  40. }
  41. fmt.Println("stop")
  42. stop <- true
  43. <-stop
  44. }