github.com/lfch/etcd-io/tests/v3@v3.0.0-20221004140520-eac99acd3e9d/functional/tester/cluster_test.go (about)

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