cluster_config_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package test
  2. import (
  3. "bytes"
  4. "os"
  5. "testing"
  6. "time"
  7. "github.com/coreos/etcd/tests"
  8. "github.com/coreos/etcd/third_party/github.com/stretchr/testify/assert"
  9. )
  10. // Ensure that the cluster configuration can be reloaded.
  11. func TestClusterConfigReload(t *testing.T) {
  12. procAttr := &os.ProcAttr{Files: []*os.File{nil, os.Stdout, os.Stderr}}
  13. argGroup, etcds, err := CreateCluster(3, procAttr, false)
  14. assert.NoError(t, err)
  15. defer DestroyCluster(etcds)
  16. resp, _ := tests.Put("http://localhost:7001/v2/admin/config", "application/json", bytes.NewBufferString(`{"activeSize":3, "removeDelay":60}`))
  17. assert.Equal(t, resp.StatusCode, 200)
  18. time.Sleep(1 * time.Second)
  19. resp, _ = tests.Get("http://localhost:7002/v2/admin/config")
  20. body := tests.ReadBodyJSON(resp)
  21. assert.Equal(t, resp.StatusCode, 200)
  22. assert.Equal(t, resp.Header.Get("Content-Type"), "application/json")
  23. assert.Equal(t, body["activeSize"], 3)
  24. assert.Equal(t, body["removeDelay"], 60)
  25. // kill all
  26. DestroyCluster(etcds)
  27. for i := 0; i < 3; i++ {
  28. etcds[i], err = os.StartProcess(EtcdBinPath, argGroup[i], procAttr)
  29. }
  30. time.Sleep(1 * time.Second)
  31. resp, _ = tests.Get("http://localhost:7002/v2/admin/config")
  32. body = tests.ReadBodyJSON(resp)
  33. assert.Equal(t, resp.StatusCode, 200)
  34. assert.Equal(t, resp.Header.Get("Content-Type"), "application/json")
  35. assert.Equal(t, body["activeSize"], 3)
  36. assert.Equal(t, body["removeDelay"], 60)
  37. }