cluster_test.go 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. "go.etcd.io/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. EtcdExec: "./bin/etcd",
  27. AgentAddr: "127.0.0.1:19027",
  28. FailpointHTTPAddr: "http://127.0.0.1:7381",
  29. BaseDir: "/tmp/etcd-functional-1",
  30. EtcdClientProxy: false,
  31. EtcdPeerProxy: true,
  32. EtcdClientEndpoint: "127.0.0.1:1379",
  33. Etcd: &rpcpb.Etcd{
  34. Name: "s1",
  35. DataDir: "/tmp/etcd-functional-1/etcd.data",
  36. WALDir: "/tmp/etcd-functional-1/etcd.data/member/wal",
  37. HeartbeatIntervalMs: 100,
  38. ElectionTimeoutMs: 1000,
  39. ListenClientURLs: []string{"https://127.0.0.1:1379"},
  40. AdvertiseClientURLs: []string{"https://127.0.0.1:1379"},
  41. ClientAutoTLS: true,
  42. ClientCertAuth: false,
  43. ClientCertFile: "",
  44. ClientKeyFile: "",
  45. ClientTrustedCAFile: "",
  46. ListenPeerURLs: []string{"https://127.0.0.1:1380"},
  47. AdvertisePeerURLs: []string{"https://127.0.0.1:1381"},
  48. PeerAutoTLS: true,
  49. PeerClientCertAuth: false,
  50. PeerCertFile: "",
  51. PeerKeyFile: "",
  52. PeerTrustedCAFile: "",
  53. InitialCluster: "s1=https://127.0.0.1:1381,s2=https://127.0.0.1:2381,s3=https://127.0.0.1:3381",
  54. InitialClusterState: "new",
  55. InitialClusterToken: "tkn",
  56. SnapshotCount: 10000,
  57. QuotaBackendBytes: 10740000000,
  58. PreVote: true,
  59. InitialCorruptCheck: true,
  60. Logger: "zap",
  61. LogOutputs: []string{"/tmp/etcd-functional-1/etcd.log"},
  62. },
  63. ClientCertData: "",
  64. ClientCertPath: "",
  65. ClientKeyData: "",
  66. ClientKeyPath: "",
  67. ClientTrustedCAData: "",
  68. ClientTrustedCAPath: "",
  69. PeerCertData: "",
  70. PeerCertPath: "",
  71. PeerKeyData: "",
  72. PeerKeyPath: "",
  73. PeerTrustedCAData: "",
  74. PeerTrustedCAPath: "",
  75. SnapshotPath: "/tmp/etcd-functional-1.snapshot.db",
  76. },
  77. {
  78. EtcdExec: "./bin/etcd",
  79. AgentAddr: "127.0.0.1:29027",
  80. FailpointHTTPAddr: "http://127.0.0.1:7382",
  81. BaseDir: "/tmp/etcd-functional-2",
  82. EtcdClientProxy: false,
  83. EtcdPeerProxy: true,
  84. EtcdClientEndpoint: "127.0.0.1:2379",
  85. Etcd: &rpcpb.Etcd{
  86. Name: "s2",
  87. DataDir: "/tmp/etcd-functional-2/etcd.data",
  88. WALDir: "/tmp/etcd-functional-2/etcd.data/member/wal",
  89. HeartbeatIntervalMs: 100,
  90. ElectionTimeoutMs: 1000,
  91. ListenClientURLs: []string{"https://127.0.0.1:2379"},
  92. AdvertiseClientURLs: []string{"https://127.0.0.1:2379"},
  93. ClientAutoTLS: true,
  94. ClientCertAuth: false,
  95. ClientCertFile: "",
  96. ClientKeyFile: "",
  97. ClientTrustedCAFile: "",
  98. ListenPeerURLs: []string{"https://127.0.0.1:2380"},
  99. AdvertisePeerURLs: []string{"https://127.0.0.1:2381"},
  100. PeerAutoTLS: true,
  101. PeerClientCertAuth: false,
  102. PeerCertFile: "",
  103. PeerKeyFile: "",
  104. PeerTrustedCAFile: "",
  105. InitialCluster: "s1=https://127.0.0.1:1381,s2=https://127.0.0.1:2381,s3=https://127.0.0.1:3381",
  106. InitialClusterState: "new",
  107. InitialClusterToken: "tkn",
  108. SnapshotCount: 10000,
  109. QuotaBackendBytes: 10740000000,
  110. PreVote: true,
  111. InitialCorruptCheck: true,
  112. Logger: "zap",
  113. LogOutputs: []string{"/tmp/etcd-functional-2/etcd.log"},
  114. },
  115. ClientCertData: "",
  116. ClientCertPath: "",
  117. ClientKeyData: "",
  118. ClientKeyPath: "",
  119. ClientTrustedCAData: "",
  120. ClientTrustedCAPath: "",
  121. PeerCertData: "",
  122. PeerCertPath: "",
  123. PeerKeyData: "",
  124. PeerKeyPath: "",
  125. PeerTrustedCAData: "",
  126. PeerTrustedCAPath: "",
  127. SnapshotPath: "/tmp/etcd-functional-2.snapshot.db",
  128. },
  129. {
  130. EtcdExec: "./bin/etcd",
  131. AgentAddr: "127.0.0.1:39027",
  132. FailpointHTTPAddr: "http://127.0.0.1:7383",
  133. BaseDir: "/tmp/etcd-functional-3",
  134. EtcdClientProxy: false,
  135. EtcdPeerProxy: true,
  136. EtcdClientEndpoint: "127.0.0.1:3379",
  137. Etcd: &rpcpb.Etcd{
  138. Name: "s3",
  139. DataDir: "/tmp/etcd-functional-3/etcd.data",
  140. WALDir: "/tmp/etcd-functional-3/etcd.data/member/wal",
  141. HeartbeatIntervalMs: 100,
  142. ElectionTimeoutMs: 1000,
  143. ListenClientURLs: []string{"https://127.0.0.1:3379"},
  144. AdvertiseClientURLs: []string{"https://127.0.0.1:3379"},
  145. ClientAutoTLS: true,
  146. ClientCertAuth: false,
  147. ClientCertFile: "",
  148. ClientKeyFile: "",
  149. ClientTrustedCAFile: "",
  150. ListenPeerURLs: []string{"https://127.0.0.1:3380"},
  151. AdvertisePeerURLs: []string{"https://127.0.0.1:3381"},
  152. PeerAutoTLS: true,
  153. PeerClientCertAuth: false,
  154. PeerCertFile: "",
  155. PeerKeyFile: "",
  156. PeerTrustedCAFile: "",
  157. InitialCluster: "s1=https://127.0.0.1:1381,s2=https://127.0.0.1:2381,s3=https://127.0.0.1:3381",
  158. InitialClusterState: "new",
  159. InitialClusterToken: "tkn",
  160. SnapshotCount: 10000,
  161. QuotaBackendBytes: 10740000000,
  162. PreVote: true,
  163. InitialCorruptCheck: true,
  164. Logger: "zap",
  165. LogOutputs: []string{"/tmp/etcd-functional-3/etcd.log"},
  166. },
  167. ClientCertData: "",
  168. ClientCertPath: "",
  169. ClientKeyData: "",
  170. ClientKeyPath: "",
  171. ClientTrustedCAData: "",
  172. ClientTrustedCAPath: "",
  173. PeerCertData: "",
  174. PeerCertPath: "",
  175. PeerKeyData: "",
  176. PeerKeyPath: "",
  177. PeerTrustedCAData: "",
  178. PeerTrustedCAPath: "",
  179. SnapshotPath: "/tmp/etcd-functional-3.snapshot.db",
  180. },
  181. },
  182. Tester: &rpcpb.Tester{
  183. DataDir: "/tmp/etcd-tester-data",
  184. Network: "tcp",
  185. Addr: "127.0.0.1:9028",
  186. DelayLatencyMs: 5000,
  187. DelayLatencyMsRv: 500,
  188. UpdatedDelayLatencyMs: 5000,
  189. RoundLimit: 1,
  190. ExitOnCaseFail: true,
  191. EnablePprof: true,
  192. CaseDelayMs: 7000,
  193. CaseShuffle: true,
  194. Cases: []string{
  195. "SIGTERM_ONE_FOLLOWER",
  196. "SIGTERM_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT",
  197. "SIGTERM_LEADER",
  198. "SIGTERM_LEADER_UNTIL_TRIGGER_SNAPSHOT",
  199. "SIGTERM_QUORUM",
  200. "SIGTERM_ALL",
  201. "SIGQUIT_AND_REMOVE_ONE_FOLLOWER",
  202. "SIGQUIT_AND_REMOVE_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT",
  203. // "SIGQUIT_AND_REMOVE_LEADER",
  204. // "SIGQUIT_AND_REMOVE_LEADER_UNTIL_TRIGGER_SNAPSHOT",
  205. // "SIGQUIT_AND_REMOVE_QUORUM_AND_RESTORE_LEADER_SNAPSHOT_FROM_SCRATCH",
  206. // "BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER",
  207. // "BLACKHOLE_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT",
  208. "BLACKHOLE_PEER_PORT_TX_RX_LEADER",
  209. "BLACKHOLE_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT",
  210. "BLACKHOLE_PEER_PORT_TX_RX_QUORUM",
  211. "BLACKHOLE_PEER_PORT_TX_RX_ALL",
  212. // "DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER",
  213. // "RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER",
  214. // "DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT",
  215. // "RANDOM_DELAY_PEER_PORT_TX_RX_ONE_FOLLOWER_UNTIL_TRIGGER_SNAPSHOT",
  216. "DELAY_PEER_PORT_TX_RX_LEADER",
  217. "RANDOM_DELAY_PEER_PORT_TX_RX_LEADER",
  218. "DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT",
  219. "RANDOM_DELAY_PEER_PORT_TX_RX_LEADER_UNTIL_TRIGGER_SNAPSHOT",
  220. "DELAY_PEER_PORT_TX_RX_QUORUM",
  221. "RANDOM_DELAY_PEER_PORT_TX_RX_QUORUM",
  222. "DELAY_PEER_PORT_TX_RX_ALL",
  223. "RANDOM_DELAY_PEER_PORT_TX_RX_ALL",
  224. "NO_FAIL_WITH_STRESS",
  225. "NO_FAIL_WITH_NO_STRESS_FOR_LIVENESS",
  226. },
  227. FailpointCommands: []string{`panic("etcd-tester")`},
  228. RunnerExecPath: "./bin/etcd-runner",
  229. ExternalExecPath: "",
  230. Stressers: []*rpcpb.Stresser{
  231. {Type: "KV_WRITE_SMALL", Weight: 0.35},
  232. {Type: "KV_WRITE_LARGE", Weight: 0.002},
  233. {Type: "KV_READ_ONE_KEY", Weight: 0.07},
  234. {Type: "KV_READ_RANGE", Weight: 0.07},
  235. {Type: "KV_DELETE_ONE_KEY", Weight: 0.07},
  236. {Type: "KV_DELETE_RANGE", Weight: 0.07},
  237. {Type: "KV_TXN_WRITE_DELETE", Weight: 0.35},
  238. {Type: "LEASE", Weight: 0.0},
  239. },
  240. Checkers: []string{"KV_HASH", "LEASE_EXPIRE"},
  241. StressKeySize: 100,
  242. StressKeySizeLarge: 32769,
  243. StressKeySuffixRange: 250000,
  244. StressKeySuffixRangeTxn: 100,
  245. StressKeyTxnOps: 10,
  246. StressClients: 100,
  247. StressQPS: 2000,
  248. },
  249. }
  250. logger, err := zap.NewProduction()
  251. if err != nil {
  252. t.Fatal(err)
  253. }
  254. defer logger.Sync()
  255. cfg, err := read(logger, "../../functional.yaml")
  256. if err != nil {
  257. t.Fatal(err)
  258. }
  259. cfg.lg = nil
  260. if !reflect.DeepEqual(exp, cfg) {
  261. t.Fatalf("expected %+v, got %+v", exp, cfg)
  262. }
  263. cfg.lg = logger
  264. cfg.updateCases()
  265. fs1 := cfg.listCases()
  266. cfg.shuffleCases()
  267. fs2 := cfg.listCases()
  268. if reflect.DeepEqual(fs1, fs2) {
  269. t.Fatalf("expected shuffled failure cases, got %q", fs2)
  270. }
  271. cfg.shuffleCases()
  272. fs3 := cfg.listCases()
  273. if reflect.DeepEqual(fs2, fs3) {
  274. t.Fatalf("expected reshuffled failure cases from %q, got %q", fs2, fs3)
  275. }
  276. // shuffle ensures visit all exactly once
  277. // so when sorted, failure cases must be equal
  278. sort.Strings(fs1)
  279. sort.Strings(fs2)
  280. sort.Strings(fs3)
  281. if !reflect.DeepEqual(fs1, fs2) {
  282. t.Fatalf("expected %q, got %q", fs1, fs2)
  283. }
  284. if !reflect.DeepEqual(fs2, fs3) {
  285. t.Fatalf("expected %q, got %q", fs2, fs3)
  286. }
  287. }