cluster_test.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. "sort"
  18. "testing"
  19. "github.com/coreos/etcd/functional/rpcpb"
  20. "go.uber.org/zap"
  21. )
  22. func Test_read(t *testing.T) {
  23. exp := &Cluster{
  24. Members: []*rpcpb.Member{
  25. {
  26. EtcdExecPath: "./bin/etcd",
  27. AgentAddr: "127.0.0.1:19027",
  28. FailpointHTTPAddr: "http://127.0.0.1:7381",
  29. BaseDir: "/tmp/etcd-agent-data-1",
  30. EtcdLogPath: "/tmp/etcd-agent-data-1/current-etcd.log",
  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. HeartbeatIntervalMs: 100,
  39. ElectionTimeoutMs: 1000,
  40. ListenClientURLs: []string{"https://127.0.0.1:1379"},
  41. AdvertiseClientURLs: []string{"https://127.0.0.1:1379"},
  42. ClientAutoTLS: true,
  43. ClientCertAuth: false,
  44. ClientCertFile: "",
  45. ClientKeyFile: "",
  46. ClientTrustedCAFile: "",
  47. ListenPeerURLs: []string{"https://127.0.0.1:1380"},
  48. AdvertisePeerURLs: []string{"https://127.0.0.1:13800"},
  49. PeerAutoTLS: true,
  50. PeerClientCertAuth: false,
  51. PeerCertFile: "",
  52. PeerKeyFile: "",
  53. PeerTrustedCAFile: "",
  54. InitialCluster: "s1=https://127.0.0.1:13800,s2=https://127.0.0.1:23800,s3=https://127.0.0.1:33800",
  55. InitialClusterState: "new",
  56. InitialClusterToken: "tkn",
  57. SnapshotCount: 10000,
  58. QuotaBackendBytes: 10740000000,
  59. PreVote: true,
  60. InitialCorruptCheck: true,
  61. },
  62. },
  63. {
  64. EtcdExecPath: "./bin/etcd",
  65. AgentAddr: "127.0.0.1:29027",
  66. FailpointHTTPAddr: "http://127.0.0.1:7382",
  67. BaseDir: "/tmp/etcd-agent-data-2",
  68. EtcdLogPath: "/tmp/etcd-agent-data-2/current-etcd.log",
  69. EtcdClientProxy: false,
  70. EtcdPeerProxy: true,
  71. EtcdClientEndpoint: "127.0.0.1:2379",
  72. Etcd: &rpcpb.Etcd{
  73. Name: "s2",
  74. DataDir: "/tmp/etcd-agent-data-2/etcd.data",
  75. WALDir: "/tmp/etcd-agent-data-2/etcd.data/member/wal",
  76. HeartbeatIntervalMs: 100,
  77. ElectionTimeoutMs: 1000,
  78. ListenClientURLs: []string{"https://127.0.0.1:2379"},
  79. AdvertiseClientURLs: []string{"https://127.0.0.1:2379"},
  80. ClientAutoTLS: true,
  81. ClientCertAuth: false,
  82. ClientCertFile: "",
  83. ClientKeyFile: "",
  84. ClientTrustedCAFile: "",
  85. ListenPeerURLs: []string{"https://127.0.0.1:2380"},
  86. AdvertisePeerURLs: []string{"https://127.0.0.1:23800"},
  87. PeerAutoTLS: true,
  88. PeerClientCertAuth: false,
  89. PeerCertFile: "",
  90. PeerKeyFile: "",
  91. PeerTrustedCAFile: "",
  92. InitialCluster: "s1=https://127.0.0.1:13800,s2=https://127.0.0.1:23800,s3=https://127.0.0.1:33800",
  93. InitialClusterState: "new",
  94. InitialClusterToken: "tkn",
  95. SnapshotCount: 10000,
  96. QuotaBackendBytes: 10740000000,
  97. PreVote: true,
  98. InitialCorruptCheck: true,
  99. },
  100. },
  101. {
  102. EtcdExecPath: "./bin/etcd",
  103. AgentAddr: "127.0.0.1:39027",
  104. FailpointHTTPAddr: "http://127.0.0.1:7383",
  105. BaseDir: "/tmp/etcd-agent-data-3",
  106. EtcdLogPath: "/tmp/etcd-agent-data-3/current-etcd.log",
  107. EtcdClientProxy: false,
  108. EtcdPeerProxy: true,
  109. EtcdClientEndpoint: "127.0.0.1:3379",
  110. Etcd: &rpcpb.Etcd{
  111. Name: "s3",
  112. DataDir: "/tmp/etcd-agent-data-3/etcd.data",
  113. WALDir: "/tmp/etcd-agent-data-3/etcd.data/member/wal",
  114. HeartbeatIntervalMs: 100,
  115. ElectionTimeoutMs: 1000,
  116. ListenClientURLs: []string{"https://127.0.0.1:3379"},
  117. AdvertiseClientURLs: []string{"https://127.0.0.1:3379"},
  118. ClientAutoTLS: true,
  119. ClientCertAuth: false,
  120. ClientCertFile: "",
  121. ClientKeyFile: "",
  122. ClientTrustedCAFile: "",
  123. ListenPeerURLs: []string{"https://127.0.0.1:3380"},
  124. AdvertisePeerURLs: []string{"https://127.0.0.1:33800"},
  125. PeerAutoTLS: true,
  126. PeerClientCertAuth: false,
  127. PeerCertFile: "",
  128. PeerKeyFile: "",
  129. PeerTrustedCAFile: "",
  130. InitialCluster: "s1=https://127.0.0.1:13800,s2=https://127.0.0.1:23800,s3=https://127.0.0.1:33800",
  131. InitialClusterState: "new",
  132. InitialClusterToken: "tkn",
  133. SnapshotCount: 10000,
  134. QuotaBackendBytes: 10740000000,
  135. PreVote: true,
  136. InitialCorruptCheck: true,
  137. },
  138. },
  139. },
  140. Tester: &rpcpb.Tester{
  141. DataDir: "/tmp/etcd-tester-data",
  142. Network: "tcp",
  143. Addr: "127.0.0.1:9028",
  144. DelayLatencyMs: 5000,
  145. DelayLatencyMsRv: 500,
  146. UpdatedDelayLatencyMs: 5000,
  147. RoundLimit: 1,
  148. ExitOnFailure: true,
  149. ConsistencyCheck: true,
  150. EnablePprof: true,
  151. FailureDelayMs: 7000,
  152. FailureShuffle: true,
  153. FailureCases: []string{
  154. "SIGTERM_ONE_FOLLOWER",
  155. "SIGTERM_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT",
  156. "SIGTERM_LEADER",
  157. "SIGTERM_LEADER_UNTIL_TRIGGER_SNAPSHOT",
  158. "SIGTERM_QUORUM",
  159. "SIGTERM_ALL",
  160. "SIGQUIT_AND_REMOVE_ONE_FOLLOWER",
  161. "SIGQUIT_AND_REMOVE_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT",
  162. // "SIGQUIT_AND_REMOVE_LEADER",
  163. // "SIGQUIT_AND_REMOVE_LEADER_UNTIL_TRIGGER_SNAPSHOT",
  164. "BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER",
  165. "BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT",
  166. "BLACKHOLE_PEER_PORT_TX_RX_LEADER",
  167. "BLACKHOLE_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT",
  168. "BLACKHOLE_PEER_PORT_TX_RX_QUORUM",
  169. "BLACKHOLE_PEER_PORT_TX_RX_ALL",
  170. "DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER",
  171. "RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER",
  172. "DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT",
  173. "RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT",
  174. "DELAY_PEER_PORT_TX_RX_LEADER",
  175. "RANDOM_DELAY_PEER_PORT_TX_RX_LEADER",
  176. "DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT",
  177. "RANDOM_DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT",
  178. "DELAY_PEER_PORT_TX_RX_QUORUM",
  179. "RANDOM_DELAY_PEER_PORT_TX_RX_QUORUM",
  180. "DELAY_PEER_PORT_TX_RX_ALL",
  181. "RANDOM_DELAY_PEER_PORT_TX_RX_ALL",
  182. "NO_FAIL_WITH_STRESS",
  183. "NO_FAIL_WITH_NO_STRESS_FOR_LIVENESS",
  184. },
  185. FailpointCommands: []string{`panic("etcd-tester")`},
  186. RunnerExecPath: "./bin/etcd-runner",
  187. ExternalExecPath: "",
  188. StressTypes: []string{"KV", "LEASE"},
  189. StressKeySize: 100,
  190. StressKeySizeLarge: 32769,
  191. StressKeySuffixRange: 250000,
  192. StressKeySuffixRangeTxn: 100,
  193. StressKeyTxnOps: 10,
  194. StressClients: 100,
  195. StressQPS: 2000,
  196. },
  197. }
  198. logger, err := zap.NewProduction()
  199. if err != nil {
  200. t.Fatal(err)
  201. }
  202. defer logger.Sync()
  203. cfg, err := read(logger, "../../functional.yaml")
  204. if err != nil {
  205. t.Fatal(err)
  206. }
  207. cfg.lg = nil
  208. if !reflect.DeepEqual(exp, cfg) {
  209. t.Fatalf("expected %+v, got %+v", exp, cfg)
  210. }
  211. cfg.lg = logger
  212. cfg.updateFailures()
  213. fs1 := cfg.failureStrings()
  214. cfg.shuffleFailures()
  215. fs2 := cfg.failureStrings()
  216. if reflect.DeepEqual(fs1, fs2) {
  217. t.Fatalf("expected shuffled failure cases, got %q", fs2)
  218. }
  219. cfg.shuffleFailures()
  220. fs3 := cfg.failureStrings()
  221. if reflect.DeepEqual(fs2, fs3) {
  222. t.Fatalf("expected reshuffled failure cases from %q, got %q", fs2, fs3)
  223. }
  224. // shuffle ensures visit all exactly once
  225. // so when sorted, failure cases must be equal
  226. sort.Strings(fs1)
  227. sort.Strings(fs2)
  228. sort.Strings(fs3)
  229. if !reflect.DeepEqual(fs1, fs2) {
  230. t.Fatalf("expected %q, got %q", fs1, fs2)
  231. }
  232. if !reflect.DeepEqual(fs2, fs3) {
  233. t.Fatalf("expected %q, got %q", fs2, fs3)
  234. }
  235. }