-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
watchers_federation_test.go
100 lines (88 loc) · 4.42 KB
/
watchers_federation_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
*
* Copyright 2021 gRPC 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
*
* https://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 xdsclient
import (
"context"
"testing"
"google.golang.org/grpc/internal/envconfig"
"google.golang.org/grpc/xds/internal/testutils"
"google.golang.org/grpc/xds/internal/xdsclient/xdsresource"
)
func overrideFedEnvVar(t *testing.T) {
oldFed := envconfig.XDSFederation
envconfig.XDSFederation = true
t.Cleanup(func() { envconfig.XDSFederation = oldFed })
}
func testFedTwoWatchDifferentContextParameterOrder(t *testing.T, typ xdsresource.ResourceType, update interface{}) {
overrideFedEnvVar(t)
var (
// Two resource names only differ in context parameter __order__.
resourceName1 = testutils.BuildResourceName(typ, testAuthority, "test-resource-name", nil) + "?a=1&b=2"
resourceName2 = testutils.BuildResourceName(typ, testAuthority, "test-resource-name", nil) + "?b=2&a=1"
)
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()
client, ctrlCh := testClientSetup(t, false)
updateCh, _ := newWatch(t, client, typ, resourceName1)
_, updateHandler := getControllerAndPubsub(ctx, t, client, ctrlCh, typ, resourceName1)
newWatchF, newUpdateF, verifyUpdateF := typeToTestFuncs(typ)
// Start a watch on the second resource name.
updateCh2, _ := newWatchF(client, resourceName2)
// Send an update on the first resoruce, both watchers should be updated.
newUpdateF(updateHandler, map[string]interface{}{resourceName1: update})
verifyUpdateF(ctx, t, updateCh, update, nil)
verifyUpdateF(ctx, t, updateCh2, update, nil)
}
// TestLDSFedTwoWatchDifferentContextParameterOrder covers the case with new style resource name
// - Two watches with the same query string, but in different order. The two
// watches should watch the same resource.
// - The response has the same query string, but in different order. The watch
// should still be notified.
func (s) TestLDSFedTwoWatchDifferentContextParameterOrder(t *testing.T) {
testFedTwoWatchDifferentContextParameterOrder(t, xdsresource.ListenerResource, xdsresource.ListenerUpdate{RouteConfigName: testRDSName})
}
// TestRDSFedTwoWatchDifferentContextParameterOrder covers the case with new style resource name
// - Two watches with the same query string, but in different order. The two
// watches should watch the same resource.
// - The response has the same query string, but in different order. The watch
// should still be notified.
func (s) TestRDSFedTwoWatchDifferentContextParameterOrder(t *testing.T) {
testFedTwoWatchDifferentContextParameterOrder(t, xdsresource.RouteConfigResource, xdsresource.RouteConfigUpdate{
VirtualHosts: []*xdsresource.VirtualHost{
{
Domains: []string{testLDSName},
Routes: []*xdsresource.Route{{Prefix: newStringP(""), WeightedClusters: map[string]xdsresource.WeightedCluster{testCDSName: {Weight: 1}}}},
},
},
})
}
// TestClusterFedTwoWatchDifferentContextParameterOrder covers the case with new style resource name
// - Two watches with the same query string, but in different order. The two
// watches should watch the same resource.
// - The response has the same query string, but in different order. The watch
// should still be notified.
func (s) TestClusterFedTwoWatchDifferentContextParameterOrder(t *testing.T) {
testFedTwoWatchDifferentContextParameterOrder(t, xdsresource.ClusterResource, xdsresource.ClusterUpdate{ClusterName: testEDSName})
}
// TestEndpointsFedTwoWatchDifferentContextParameterOrder covers the case with new style resource name
// - Two watches with the same query string, but in different order. The two
// watches should watch the same resource.
// - The response has the same query string, but in different order. The watch
// should still be notified.
func (s) TestEndpointsFedTwoWatchDifferentContextParameterOrder(t *testing.T) {
testFedTwoWatchDifferentContextParameterOrder(t, xdsresource.EndpointsResource, xdsresource.EndpointsUpdate{Localities: []xdsresource.Locality{testLocalities[0]}})
}