github.com/jpetazzo/etcd@v0.2.1-0.20140113055439-97f1363afac5/tests/functional/multi_node_kill_one_test.go (about)

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