v1_migration_test.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package test
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "os"
  6. "os/exec"
  7. "path/filepath"
  8. "testing"
  9. "time"
  10. "github.com/coreos/etcd/tests"
  11. "github.com/stretchr/testify/assert"
  12. )
  13. // Ensure that we can start a v2 node from the log of a v1 node.
  14. func TestV1Migration(t *testing.T) {
  15. path, _ := ioutil.TempDir("", "etcd-")
  16. os.RemoveAll(path)
  17. defer os.RemoveAll(path)
  18. nodes := []string{"node0", "node2"}
  19. for i, node := range nodes {
  20. nodepath := filepath.Join(path, node)
  21. fixturepath, _ := filepath.Abs(filepath.Join("../fixtures/v1/", node))
  22. fmt.Println("FIXPATH =", fixturepath)
  23. fmt.Println("NODEPATH =", nodepath)
  24. os.MkdirAll(filepath.Dir(nodepath), 0777)
  25. // Copy over fixture files.
  26. c := exec.Command("cp", "-rf", fixturepath, nodepath)
  27. if out, err := c.CombinedOutput(); err != nil {
  28. fmt.Println(">>>>>>\n", string(out), "<<<<<<")
  29. panic("Fixture initialization error:" + err.Error())
  30. }
  31. procAttr := new(os.ProcAttr)
  32. procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
  33. args := []string{"etcd", fmt.Sprintf("-d=%s", nodepath)}
  34. args = append(args, "-c", fmt.Sprintf("127.0.0.1:%d", 4001 + i))
  35. args = append(args, "-s", fmt.Sprintf("127.0.0.1:%d", 7001 + i))
  36. process, err := os.StartProcess(EtcdBinPath, args, procAttr)
  37. if err != nil {
  38. t.Fatal("start process failed:" + err.Error())
  39. return
  40. }
  41. defer process.Kill()
  42. time.Sleep(time.Second)
  43. }
  44. time.Sleep(120 * time.Second)
  45. // Ensure deleted message is removed.
  46. resp, err := tests.Get("http://localhost:4001/v2/keys/message")
  47. tests.ReadBody(resp)
  48. assert.Nil(t, err, "")
  49. assert.Equal(t, resp.StatusCode, 404, "")
  50. // Ensure TTL'd message is removed.
  51. resp, err = tests.Get("http://localhost:4001/v2/keys/foo")
  52. tests.ReadBody(resp)
  53. assert.Nil(t, err, "")
  54. assert.Equal(t, resp.StatusCode, 404, "")
  55. }