-
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.
Signed-off-by: Chao Chen <chaochn@amazon.com>
- Loading branch information
Showing
8 changed files
with
156 additions
and
34 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2023 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 failpoint | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
// TestMemberPromoteMemberNotLearnerWithFailpoint ensures that promoting a voting member fails with injected failpoint . | ||
// make gofail-enable && pushd tests/failpoint && go test -v -run TestMemberPromoteMemberNotLearnerWithFailpoint && popd | ||
func TestMemberPromoteMemberNotLearnerWithFailpoint(t *testing.T) { | ||
MemberPromoteMemberNotLearnerTest(t, NewFailpoint("raftBeforeAdvance", `sleep(100)`)) | ||
} |
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,64 @@ | ||
// Copyright 2023 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 failpoint | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
integration2 "go.etcd.io/etcd/tests/v3/framework/integration" | ||
) | ||
|
||
func MemberPromoteMemberNotLearnerTest(t *testing.T, f Failpoint) { | ||
integration2.BeforeTest(t) | ||
|
||
require.NoError(t, f.Enable()) | ||
defer func() { | ||
require.NoError(t, f.Disable()) | ||
}() | ||
|
||
clus := integration2.NewCluster(t, &integration2.ClusterConfig{Size: 3}) | ||
defer clus.Terminate(t) | ||
// member promote request can be sent to any server in cluster, | ||
// the request will be auto-forwarded to leader on server-side. | ||
// This test explicitly includes the server-side forwarding by | ||
// sending the request to follower. | ||
leaderIdx := clus.WaitLeader(t) | ||
followerIdx := (leaderIdx + 1) % 3 | ||
cli := clus.Client(followerIdx) | ||
|
||
resp, err := cli.MemberList(context.Background()) | ||
if err != nil { | ||
t.Fatalf("failed to list member %v", err) | ||
} | ||
if len(resp.Members) != 3 { | ||
t.Fatalf("number of members = %d, want %d", len(resp.Members), 3) | ||
} | ||
|
||
// promoting any of the voting members in cluster should fail | ||
expectedErrKeywords := "can only promote a learner member" | ||
for _, m := range resp.Members { | ||
_, err = cli.MemberPromote(context.Background(), m.ID) | ||
if err == nil { | ||
t.Fatalf("expect promoting voting member to fail, got no error") | ||
} | ||
if !strings.Contains(err.Error(), expectedErrKeywords) { | ||
t.Fatalf("expect error to contain %s, got %s", expectedErrKeywords, err.Error()) | ||
} | ||
} | ||
} |
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,49 @@ | ||
// Copyright 2023 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 failpoint | ||
|
||
import ( | ||
gofail "go.etcd.io/gofail/runtime" | ||
) | ||
|
||
var EmptyFailPoint = &failpointFunc{} | ||
|
||
type Failpoint interface { | ||
Enable() error | ||
Disable() error | ||
} | ||
|
||
type failpointFunc struct { | ||
name string | ||
payload string | ||
} | ||
|
||
func (f *failpointFunc) Enable() error { | ||
if f == nil || len(f.name) == 0 { | ||
return nil | ||
} | ||
return gofail.Enable(f.name, f.payload) | ||
} | ||
|
||
func (f *failpointFunc) Disable() error { | ||
if f == nil || len(f.name) == 0 { | ||
return nil | ||
} | ||
return gofail.Disable(f.name) | ||
} | ||
|
||
func NewFailpoint(name, payload string) *failpointFunc { | ||
return &failpointFunc{name, payload} | ||
} |
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