-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add WaitLeader function to common framework
Signed-off-by: Clark <[email protected]>
- Loading branch information
1 parent
a384f6f
commit 5091062
Showing
4 changed files
with
157 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright 2022 The etcd Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package common | ||
|
||
import ( | ||
"context" | ||
"go.etcd.io/etcd/tests/v3/framework/config" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestWaitLeader(t *testing.T) { | ||
testRunner.BeforeTest(t) | ||
|
||
for _, tc := range clusterTestCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
defer cancel() | ||
clus := testRunner.NewCluster(ctx, t, tc.config) | ||
defer clus.Close() | ||
|
||
leader := clus.WaitLeader(t) | ||
if leader < 0 || leader >= len(clus.Members()) { | ||
t.Fatalf("failed to wait leader") | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestWaitLeader_MemberStop(t *testing.T) { | ||
testRunner.BeforeTest(t) | ||
tcs := []testCase{ | ||
{ | ||
name: "PeerTLS", | ||
config: config.ClusterConfig{ClusterSize: 3, PeerTLS: config.ManualTLS}, | ||
}, | ||
{ | ||
name: "PeerAutoTLS", | ||
config: config.ClusterConfig{ClusterSize: 3, PeerTLS: config.AutoTLS}, | ||
}, | ||
} | ||
|
||
for _, tc := range tcs { | ||
t.Run(tc.name, func(t *testing.T) { | ||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
defer cancel() | ||
clus := testRunner.NewCluster(ctx, t, tc.config) | ||
defer clus.Close() | ||
|
||
lead1 := clus.WaitLeader(t) | ||
if lead1 < 0 || lead1 >= len(clus.Members()) { | ||
t.Fatalf("failed to wait leader") | ||
} | ||
|
||
clus.Members()[lead1].Stop() | ||
lead2 := clus.WaitLeader(t) | ||
if lead2 < 0 || lead2 >= len(clus.Members()) { | ||
t.Fatalf("failed to wait leader") | ||
} | ||
|
||
if lead1 == lead2 { | ||
t.Fatalf("leader did not change as expected after stopping memberts") | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters