proxy_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package test
  2. import (
  3. "fmt"
  4. "os"
  5. "testing"
  6. "time"
  7. "github.com/coreos/etcd/tests"
  8. "github.com/coreos/etcd/third_party/github.com/coreos/go-etcd/etcd"
  9. "github.com/coreos/etcd/third_party/github.com/stretchr/testify/assert"
  10. )
  11. // Create a full cluster and then add extra an extra proxy node.
  12. func TestProxy(t *testing.T) {
  13. clusterSize := 10 // MaxClusterSize + 1
  14. _, etcds, err := CreateCluster(clusterSize, &os.ProcAttr{Files: []*os.File{nil, os.Stdout, os.Stderr}}, false)
  15. assert.NoError(t, err)
  16. defer DestroyCluster(etcds)
  17. if err != nil {
  18. t.Fatal("cannot create cluster")
  19. }
  20. c := etcd.NewClient(nil)
  21. c.SyncCluster()
  22. // Set key.
  23. time.Sleep(time.Second)
  24. if _, err := c.Set("foo", "bar", 0); err != nil {
  25. panic(err)
  26. }
  27. time.Sleep(time.Second)
  28. // Check that all peers and proxies have the value.
  29. for i, _ := range etcds {
  30. resp, err := tests.Get(fmt.Sprintf("http://localhost:%d/v2/keys/foo", 4000 + (i+1)))
  31. if assert.NoError(t, err) {
  32. body := tests.ReadBodyJSON(resp)
  33. if node, _ := body["node"].(map[string]interface{}); assert.NotNil(t, node) {
  34. assert.Equal(t, node["value"], "bar")
  35. }
  36. }
  37. }
  38. }