main.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright 2015 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package main
  15. import (
  16. "flag"
  17. "fmt"
  18. "net/http"
  19. "strings"
  20. "github.com/coreos/pkg/capnslog"
  21. "github.com/prometheus/client_golang/prometheus"
  22. )
  23. var plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "etcd-tester")
  24. func main() {
  25. endpointStr := flag.String("agent-endpoints", "localhost:9027", "HTTP RPC endpoints of agents. Do not specify the schema.")
  26. datadir := flag.String("data-dir", "agent.etcd", "etcd data directory location on agent machine.")
  27. stressKeySize := flag.Int("stress-key-size", 100, "the size of each key written into etcd.")
  28. stressKeySuffixRange := flag.Int("stress-key-count", 250000, "the count of key range written into etcd.")
  29. limit := flag.Int("limit", -1, "the limit of rounds to run failure set (-1 to run without limits).")
  30. schedCases := flag.String("schedule-cases", "", "test case schedule")
  31. consistencyCheck := flag.Bool("consistency-check", true, "true to check consistency (revision, hash)")
  32. isV2Only := flag.Bool("v2-only", false, "'true' to run V2 only tester.")
  33. flag.Parse()
  34. endpoints := strings.Split(*endpointStr, ",")
  35. c, err := newCluster(endpoints, *datadir, *stressKeySize, *stressKeySuffixRange, *isV2Only)
  36. if err != nil {
  37. plog.Fatal(err)
  38. }
  39. defer c.Terminate()
  40. failures := []failure{
  41. newFailureKillAll(),
  42. newFailureKillMajority(),
  43. newFailureKillOne(),
  44. newFailureKillLeader(),
  45. newFailureKillOneForLongTime(),
  46. newFailureKillLeaderForLongTime(),
  47. newFailureIsolate(),
  48. newFailureIsolateAll(),
  49. newFailureSlowNetworkOneMember(),
  50. newFailureSlowNetworkLeader(),
  51. newFailureSlowNetworkAll(),
  52. }
  53. schedule := failures
  54. if schedCases != nil && *schedCases != "" {
  55. cases := strings.Split(*schedCases, " ")
  56. schedule = make([]failure, len(cases))
  57. for i := range cases {
  58. caseNum := 0
  59. n, err := fmt.Sscanf(cases[i], "%d", &caseNum)
  60. if n == 0 || err != nil {
  61. plog.Fatalf(`couldn't parse case "%s" (%v)`, cases[i], err)
  62. }
  63. schedule[i] = failures[caseNum]
  64. }
  65. }
  66. t := &tester{
  67. failures: schedule,
  68. cluster: c,
  69. limit: *limit,
  70. consistencyCheck: *consistencyCheck,
  71. }
  72. sh := statusHandler{status: &t.status}
  73. http.Handle("/status", sh)
  74. http.Handle("/metrics", prometheus.Handler())
  75. go func() { plog.Fatal(http.ListenAndServe(":9028", nil)) }()
  76. t.runLoop()
  77. }