-
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.
- Loading branch information
Showing
11 changed files
with
322 additions
and
40 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
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
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,114 @@ | ||
// Copyright 2016 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 e2e | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.etcd.io/etcd/client/pkg/v3/testutil" | ||
) | ||
|
||
func TestCtlV3AuthoritySingleEndpoint(t *testing.T) { | ||
BeforeTest(t) | ||
|
||
cfg := newConfigAutoTLS() | ||
cfg.clusterSize = 1 | ||
// Enable debug mode to get logs with http2 headers (including authority) | ||
cfg.env = []string{"GODEBUG=http2debug=2"} | ||
|
||
epc, err := newEtcdProcessCluster(t, cfg) | ||
if err != nil { | ||
t.Fatalf("could not start etcd process cluster (%v)", err) | ||
} | ||
err = put(t, cfg, epc, "foo", "bar") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
executeWithTimeout(t, 5*time.Second, func() { | ||
assertAuthority(t, "#initially=[http://localhost:20000]", epc.procs[0].Logs()) | ||
}) | ||
assert.NoError(t, epc.Close()) | ||
} | ||
|
||
func TestCtlV3AuthorityMultipleEndpoints(t *testing.T) { | ||
BeforeTest(t) | ||
|
||
cfg := newConfigAutoTLS() | ||
cfg.clusterSize = 3 | ||
// Enable debug mode to get logs with http2 headers (including authority) | ||
cfg.env = []string{"GODEBUG=http2debug=2"} | ||
|
||
epc, err := newEtcdProcessCluster(t, cfg) | ||
if err != nil { | ||
t.Fatalf("could not start etcd process cluster (%v)", err) | ||
} | ||
err = put(t, cfg, epc, "foo", "bar") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
executeWithTimeout(t, 10*time.Second, func() { | ||
assertAuthority(t, "#initially=[http://localhost:20000;http://localhost:20005;http://localhost:20010]", epc.procs[0].Logs(), epc.procs[1].Logs(), epc.procs[2].Logs()) | ||
}) | ||
assert.NoError(t, epc.Close()) | ||
} | ||
|
||
func assertAuthority(t *testing.T, expectAurhority string, logs ...logsExpect) { | ||
line := firstMatch(t, `http2: decoded hpack field header field ":authority"`, logs...) | ||
line = strings.TrimSuffix(line, "\n") | ||
line = strings.TrimSuffix(line, "\r") | ||
expectLine := fmt.Sprintf(`http2: decoded hpack field header field ":authority" = %q`, expectAurhority) | ||
assert.True(t, strings.HasSuffix(line, expectLine), fmt.Sprintf("Got %q expected suffix %q", line, expectLine)) | ||
} | ||
|
||
func firstMatch(t *testing.T, expectLine string, logs ...logsExpect) string { | ||
t.Helper() | ||
match := make(chan string, len(logs)) | ||
for i := range logs { | ||
go func(l logsExpect) { | ||
line, _ := l.Expect(expectLine) | ||
match <- line | ||
}(logs[i]) | ||
} | ||
return <-match | ||
} | ||
|
||
func executeWithTimeout(t *testing.T, timeout time.Duration, f func()) { | ||
donec := make(chan struct{}) | ||
go func() { | ||
defer close(donec) | ||
f() | ||
}() | ||
|
||
select { | ||
case <-time.After(timeout): | ||
testutil.FatalStack(t, fmt.Sprintf("test timed out after %v", timeout)) | ||
case <-donec: | ||
} | ||
} | ||
|
||
func put(t *testing.T, cfg *etcdProcessClusterConfig, epc *etcdProcessCluster, key, value string) error { | ||
ctx := ctlCtx{ | ||
t: t, | ||
cfg: *cfg, | ||
epc: epc, | ||
} | ||
return ctlV3Put(ctx, key, value, "") | ||
} |
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,66 @@ | ||
// Copyright 2016 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 clientv3test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc" | ||
"go.etcd.io/etcd/tests/v3/integration" | ||
) | ||
|
||
func TestAuthoritySingleEndpoint(t *testing.T) { | ||
integration.BeforeTest(t) | ||
|
||
clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1}) | ||
defer clus.Terminate(t) | ||
|
||
kv := clus.Client(0) | ||
|
||
ctx := context.TODO() | ||
_, err := kv.Put(ctx, "foo", "bar") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
reqs := clus.Members[0].RecordedRequests() | ||
assert.ElementsMatch(t, []v3rpc.RequestInfo{{FullMethod: "/etcdserverpb.KV/Put", Authority: "#initially=[unix://localhost:m00]"}}, reqs) | ||
} | ||
|
||
func TestAuthorityMultipleEndpoints(t *testing.T) { | ||
integration.BeforeTest(t) | ||
|
||
clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 3}) | ||
defer clus.Terminate(t) | ||
|
||
kv, err := clus.ClusterClient() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
ctx := context.TODO() | ||
_, err = kv.Put(ctx, "foo", "bar") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
reqs := []v3rpc.RequestInfo{} | ||
for _, m := range clus.Members { | ||
reqs = append(reqs, m.RecordedRequests()...) | ||
} | ||
assert.ElementsMatch(t, []v3rpc.RequestInfo{{FullMethod: "/etcdserverpb.KV/Put", Authority: "#initially=[unix://localhost:m00;unix://localhost:m10;unix://localhost:m20]"}}, reqs) | ||
} |
Oops, something went wrong.