cluster_test.go 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. "BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER",
  161. "BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT",
  162. "BLACKHOLE_PEER_PORT_TX_RX_LEADER",
  163. "BLACKHOLE_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT",
  164. "BLACKHOLE_PEER_PORT_TX_RX_QUORUM",
  165. "BLACKHOLE_PEER_PORT_TX_RX_ALL",
  166. "DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER",
  167. "RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER",
  168. "DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT",
  169. "RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT",
  170. "DELAY_PEER_PORT_TX_RX_LEADER",
  171. "RANDOM_DELAY_PEER_PORT_TX_RX_LEADER",
  172. "DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT",
  173. "RANDOM_DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT",
  174. "DELAY_PEER_PORT_TX_RX_QUORUM",
  175. "RANDOM_DELAY_PEER_PORT_TX_RX_QUORUM",
  176. "DELAY_PEER_PORT_TX_RX_ALL",
  177. "RANDOM_DELAY_PEER_PORT_TX_RX_ALL",
  178. "NO_FAIL_WITH_STRESS",
  179. "NO_FAIL_WITH_NO_STRESS_FOR_LIVENESS",
  180. },
  181. FailpointCommands: []string{`panic("etcd-tester")`},
  182. RunnerExecPath: "./bin/etcd-runner",
  183. ExternalExecPath: "",
  184. StressTypes: []string{"KV", "LEASE"},
  185. StressKeySize: 100,
  186. StressKeySizeLarge: 32769,
  187. StressKeySuffixRange: 250000,
  188. StressKeySuffixRangeTxn: 100,
  189. StressKeyTxnOps: 10,
  190. StressClients: 100,
  191. StressQPS: 2000,
  192. },
  193. }
  194. logger, err := zap.NewProduction()
  195. if err != nil {
  196. t.Fatal(err)
  197. }
  198. defer logger.Sync()
  199. cfg, err := read(logger, "../../functional.yaml")
  200. if err != nil {
  201. t.Fatal(err)
  202. }
  203. cfg.lg = nil
  204. if !reflect.DeepEqual(exp, cfg) {
  205. t.Fatalf("expected %+v, got %+v", exp, cfg)
  206. }
  207. cfg.lg = logger
  208. cfg.updateFailures()
  209. fs1 := cfg.failureStrings()
  210. cfg.shuffleFailures()
  211. fs2 := cfg.failureStrings()
  212. if reflect.DeepEqual(fs1, fs2) {
  213. t.Fatalf("expected shuffled failure cases, got %q", fs2)
  214. }
  215. cfg.shuffleFailures()
  216. fs3 := cfg.failureStrings()
  217. if reflect.DeepEqual(fs2, fs3) {
  218. t.Fatalf("expected reshuffled failure cases from %q, got %q", fs2, fs3)
  219. }
  220. // shuffle ensures visit all exactly once
  221. // so when sorted, failure cases must be equal
  222. sort.Strings(fs1)
  223. sort.Strings(fs2)
  224. sort.Strings(fs3)
  225. if !reflect.DeepEqual(fs1, fs2) {
  226. t.Fatalf("expected %q, got %q", fs1, fs2)
  227. }
  228. if !reflect.DeepEqual(fs2, fs3) {
  229. t.Fatalf("expected %q, got %q", fs2, fs3)
  230. }
  231. }