Browse Source

server: move TestClusterConfigReload to etcd/

Yicheng Qin 11 years ago
parent
commit
01322cd243
2 changed files with 44 additions and 47 deletions
  1. 44 0
      etcd/etcd_functional_test.go
  2. 0 47
      tests/functional/cluster_config_test.go

+ 44 - 0
etcd/etcd_functional_test.go

@@ -20,6 +20,7 @@ import (
 	"fmt"
 	"math/rand"
 	"net/http/httptest"
+	"reflect"
 	"testing"
 	"time"
 
@@ -136,6 +137,49 @@ func TestJoinThroughFollower(t *testing.T) {
 	afterTest(t)
 }
 
+func TestClusterConfigReload(t *testing.T) {
+	tests := []int{3, 4, 5, 6}
+
+	for i, tt := range tests {
+		es, hs := buildCluster(tt, false)
+		waitCluster(t, es)
+
+		lead, _ := waitLeader(es)
+		conf := config.NewClusterConfig()
+		conf.ActiveSize = 15
+		conf.RemoveDelay = 60
+		if err := es[lead].p.setClusterConfig(conf); err != nil {
+			t.Fatalf("#%d: setClusterConfig err = %v", i, err)
+		}
+
+		for k := range es {
+			es[k].Stop()
+			hs[k].Close()
+		}
+
+		for k := range es {
+			c := config.New()
+			c.DataDir = es[k].config.DataDir
+			c.Addr = hs[k].Listener.Addr().String()
+			id := es[k].id
+			e, h, err := buildServer(t, c, id)
+			if err != nil {
+				t.Fatal(err)
+			}
+			es[k] = e
+			hs[k] = h
+		}
+
+		lead, _ = waitLeader(es)
+		if g := es[lead].p.clusterConfig(); !reflect.DeepEqual(g, conf) {
+			t.Errorf("#%d: clusterConfig = %+v, want %+v", i, g, conf)
+		}
+
+		destoryCluster(t, es, hs)
+	}
+	afterTest(t)
+}
+
 func BenchmarkEndToEndSet(b *testing.B) {
 	es, hs := buildCluster(3, false)
 	waitLeader(es)

+ 0 - 47
tests/functional/cluster_config_test.go

@@ -1,47 +0,0 @@
-package test
-
-import (
-	"bytes"
-	"os"
-	"testing"
-	"time"
-
-	"github.com/coreos/etcd/tests"
-	"github.com/coreos/etcd/third_party/github.com/stretchr/testify/assert"
-)
-
-// Ensure that the cluster configuration can be reloaded.
-func TestClusterConfigReload(t *testing.T) {
-	procAttr := &os.ProcAttr{Files: []*os.File{nil, os.Stdout, os.Stderr}}
-	argGroup, etcds, err := CreateCluster(3, procAttr, false)
-	assert.NoError(t, err)
-	defer DestroyCluster(etcds)
-
-	resp, _ := tests.Put("http://localhost:7001/v2/admin/config", "application/json", bytes.NewBufferString(`{"activeSize":3, "removeDelay":60}`))
-	assert.Equal(t, resp.StatusCode, 200)
-
-	time.Sleep(1 * time.Second)
-
-	resp, _ = tests.Get("http://localhost:7002/v2/admin/config")
-	body := tests.ReadBodyJSON(resp)
-	assert.Equal(t, resp.StatusCode, 200)
-	assert.Equal(t, resp.Header.Get("Content-Type"), "application/json")
-	assert.Equal(t, body["activeSize"], 3)
-	assert.Equal(t, body["removeDelay"], 60)
-
-	// kill all
-	DestroyCluster(etcds)
-
-	for i := 0; i < 3; i++ {
-		etcds[i], err = os.StartProcess(EtcdBinPath, argGroup[i], procAttr)
-	}
-
-	time.Sleep(1 * time.Second)
-
-	resp, _ = tests.Get("http://localhost:7002/v2/admin/config")
-	body = tests.ReadBodyJSON(resp)
-	assert.Equal(t, resp.StatusCode, 200)
-	assert.Equal(t, resp.Header.Get("Content-Type"), "application/json")
-	assert.Equal(t, body["activeSize"], 3)
-	assert.Equal(t, body["removeDelay"], 60)
-}