server_utils.go 826 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package tests
  2. import (
  3. "github.com/coreos/etcd/config"
  4. "github.com/coreos/etcd/etcd"
  5. "github.com/coreos/etcd/server"
  6. )
  7. const (
  8. testName = "ETCDTEST"
  9. testClientURL = "localhost:4401"
  10. testRaftURL = "localhost:7701"
  11. testSnapshotCount = 10000
  12. testHeartbeatInterval = 50
  13. testElectionTimeout = 200
  14. testDataDir = "/tmp/ETCDTEST"
  15. )
  16. // Starts a new server.
  17. func RunServer(f func(*server.Server)) {
  18. c := config.New()
  19. c.Name = testName
  20. c.Addr = testClientURL
  21. c.Peer.Addr = testRaftURL
  22. c.DataDir = testDataDir
  23. c.Force = true
  24. c.Peer.HeartbeatInterval = testHeartbeatInterval
  25. c.Peer.ElectionTimeout = testElectionTimeout
  26. c.SnapshotCount = testSnapshotCount
  27. i := etcd.New(c)
  28. go i.Run()
  29. <-i.ReadyNotify()
  30. // Execute the function passed in.
  31. f(i.Server)
  32. i.Stop()
  33. }