cluster_test.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. // Copyright 2018 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 tester
  15. import (
  16. "reflect"
  17. "testing"
  18. "github.com/coreos/etcd/tools/functional-tester/rpcpb"
  19. "go.uber.org/zap"
  20. )
  21. func Test_newCluster(t *testing.T) {
  22. exp := &Cluster{
  23. Members: []*rpcpb.Member{
  24. {
  25. EtcdExecPath: "./bin/etcd",
  26. AgentAddr: "127.0.0.1:19027",
  27. FailpointHTTPAddr: "http://127.0.0.1:7381",
  28. BaseDir: "/tmp/etcd-agent-data-1",
  29. EtcdLogPath: "/tmp/etcd-agent-data-1/current-etcd.log",
  30. EtcdClientTLS: false,
  31. EtcdClientProxy: false,
  32. EtcdPeerProxy: true,
  33. EtcdClientEndpoint: "127.0.0.1:1379",
  34. Etcd: &rpcpb.Etcd{
  35. Name: "s1",
  36. DataDir: "/tmp/etcd-agent-data-1/etcd.data",
  37. WALDir: "/tmp/etcd-agent-data-1/etcd.data/member/wal",
  38. ListenClientURLs: []string{"http://127.0.0.1:1379"},
  39. AdvertiseClientURLs: []string{"http://127.0.0.1:1379"},
  40. ListenPeerURLs: []string{"http://127.0.0.1:1380"},
  41. InitialAdvertisePeerURLs: []string{"http://127.0.0.1:13800"},
  42. InitialCluster: "s1=http://127.0.0.1:13800,s2=http://127.0.0.1:23800,s3=http://127.0.0.1:33800",
  43. InitialClusterState: "new",
  44. InitialClusterToken: "tkn",
  45. SnapshotCount: 10000,
  46. QuotaBackendBytes: 10740000000,
  47. PreVote: true,
  48. InitialCorruptCheck: true,
  49. },
  50. },
  51. {
  52. EtcdExecPath: "./bin/etcd",
  53. AgentAddr: "127.0.0.1:29027",
  54. FailpointHTTPAddr: "http://127.0.0.1:7382",
  55. BaseDir: "/tmp/etcd-agent-data-2",
  56. EtcdLogPath: "/tmp/etcd-agent-data-2/current-etcd.log",
  57. EtcdClientTLS: false,
  58. EtcdClientProxy: false,
  59. EtcdPeerProxy: true,
  60. EtcdClientEndpoint: "127.0.0.1:2379",
  61. Etcd: &rpcpb.Etcd{
  62. Name: "s2",
  63. DataDir: "/tmp/etcd-agent-data-2/etcd.data",
  64. WALDir: "/tmp/etcd-agent-data-2/etcd.data/member/wal",
  65. ListenClientURLs: []string{"http://127.0.0.1:2379"},
  66. AdvertiseClientURLs: []string{"http://127.0.0.1:2379"},
  67. ListenPeerURLs: []string{"http://127.0.0.1:2380"},
  68. InitialAdvertisePeerURLs: []string{"http://127.0.0.1:23800"},
  69. InitialCluster: "s1=http://127.0.0.1:13800,s2=http://127.0.0.1:23800,s3=http://127.0.0.1:33800",
  70. InitialClusterState: "new",
  71. InitialClusterToken: "tkn",
  72. SnapshotCount: 10000,
  73. QuotaBackendBytes: 10740000000,
  74. PreVote: true,
  75. InitialCorruptCheck: true,
  76. },
  77. },
  78. {
  79. EtcdExecPath: "./bin/etcd",
  80. AgentAddr: "127.0.0.1:39027",
  81. FailpointHTTPAddr: "http://127.0.0.1:7383",
  82. BaseDir: "/tmp/etcd-agent-data-3",
  83. EtcdLogPath: "/tmp/etcd-agent-data-3/current-etcd.log",
  84. EtcdClientTLS: false,
  85. EtcdClientProxy: false,
  86. EtcdPeerProxy: true,
  87. EtcdClientEndpoint: "127.0.0.1:3379",
  88. Etcd: &rpcpb.Etcd{
  89. Name: "s3",
  90. DataDir: "/tmp/etcd-agent-data-3/etcd.data",
  91. WALDir: "/tmp/etcd-agent-data-3/etcd.data/member/wal",
  92. ListenClientURLs: []string{"http://127.0.0.1:3379"},
  93. AdvertiseClientURLs: []string{"http://127.0.0.1:3379"},
  94. ListenPeerURLs: []string{"http://127.0.0.1:3380"},
  95. InitialAdvertisePeerURLs: []string{"http://127.0.0.1:33800"},
  96. InitialCluster: "s1=http://127.0.0.1:13800,s2=http://127.0.0.1:23800,s3=http://127.0.0.1:33800",
  97. InitialClusterState: "new",
  98. InitialClusterToken: "tkn",
  99. SnapshotCount: 10000,
  100. QuotaBackendBytes: 10740000000,
  101. PreVote: true,
  102. InitialCorruptCheck: true,
  103. },
  104. },
  105. },
  106. Tester: &rpcpb.Tester{
  107. TesterNetwork: "tcp",
  108. TesterAddr: "127.0.0.1:9028",
  109. DelayLatencyMs: 500,
  110. DelayLatencyMsRv: 50,
  111. RoundLimit: 1,
  112. ExitOnFailure: true,
  113. ConsistencyCheck: true,
  114. EnablePprof: true,
  115. FailureCases: []string{
  116. "KILL_ONE_FOLLOWER",
  117. "KILL_LEADER",
  118. "KILL_ONE_FOLLOWER_FOR_LONG",
  119. "KILL_LEADER_FOR_LONG",
  120. "KILL_QUORUM",
  121. "KILL_ALL",
  122. "BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER",
  123. "BLACKHOLE_PEER_PORT_TX_RX_LEADER_ONE",
  124. "BLACKHOLE_PEER_PORT_TX_RX_ALL",
  125. "DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER",
  126. "DELAY_PEER_PORT_TX_RX_LEADER",
  127. "DELAY_PEER_PORT_TX_RX_ALL",
  128. },
  129. FailureShuffle: true,
  130. FailpointCommands: []string{`panic("etcd-tester")`},
  131. RunnerExecPath: "/etcd-runner",
  132. ExternalExecPath: "",
  133. StressTypes: []string{"KV", "LEASE"},
  134. StressKeySize: 100,
  135. StressKeySizeLarge: 32769,
  136. StressKeySuffixRange: 250000,
  137. StressKeySuffixRangeTxn: 100,
  138. StressKeyTxnOps: 10,
  139. StressQPS: 1000,
  140. },
  141. }
  142. logger, err := zap.NewProduction()
  143. if err != nil {
  144. t.Fatal(err)
  145. }
  146. defer logger.Sync()
  147. cfg, err := newCluster(logger, "./local-test.yaml")
  148. if err != nil {
  149. t.Fatal(err)
  150. }
  151. cfg.logger = nil
  152. if !reflect.DeepEqual(exp, cfg) {
  153. t.Fatalf("expected %+v, got %+v", exp, cfg)
  154. }
  155. cfg.logger = logger
  156. cfg.updateFailures()
  157. fs1 := make([]string, len(cfg.failures))
  158. for i := range cfg.failures {
  159. fs1[i] = cfg.failures[i].Desc()
  160. }
  161. cfg.shuffleFailures()
  162. fs2 := make([]string, len(cfg.failures))
  163. for i := range cfg.failures {
  164. fs2[i] = cfg.failures[i].Desc()
  165. }
  166. if reflect.DeepEqual(fs1, fs2) {
  167. t.Fatalf("expected shuffled failure cases, got %q", fs2)
  168. }
  169. cfg.shuffleFailures()
  170. fs3 := make([]string, len(cfg.failures))
  171. for i := range cfg.failures {
  172. fs3[i] = cfg.failures[i].Desc()
  173. }
  174. if reflect.DeepEqual(fs2, fs3) {
  175. t.Fatalf("expected reshuffled failure cases from %q, got %q", fs2, fs3)
  176. }
  177. }