cluster_test.go 6.4 KB

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