File tree Expand file tree Collapse file tree 3 files changed +18
-11
lines changed Expand file tree Collapse file tree 3 files changed +18
-11
lines changed Original file line number Diff line number Diff line change @@ -31,26 +31,30 @@ var (
31
31
mu sync.Mutex
32
32
)
33
33
34
+ // Int implements rand.Int on the grpcrand global source.
35
+ func Int () int {
36
+ mu .Lock ()
37
+ defer mu .Unlock ()
38
+ return r .Int ()
39
+ }
40
+
34
41
// Int63n implements rand.Int63n on the grpcrand global source.
35
42
func Int63n (n int64 ) int64 {
36
43
mu .Lock ()
37
- res := r .Int63n (n )
38
- mu .Unlock ()
39
- return res
44
+ defer mu .Unlock ()
45
+ return r .Int63n (n )
40
46
}
41
47
42
48
// Intn implements rand.Intn on the grpcrand global source.
43
49
func Intn (n int ) int {
44
50
mu .Lock ()
45
- res := r .Intn (n )
46
- mu .Unlock ()
47
- return res
51
+ defer mu .Unlock ()
52
+ return r .Intn (n )
48
53
}
49
54
50
55
// Float64 implements rand.Float64 on the grpcrand global source.
51
56
func Float64 () float64 {
52
57
mu .Lock ()
53
- res := r .Float64 ()
54
- mu .Unlock ()
55
- return res
58
+ defer mu .Unlock ()
59
+ return r .Float64 ()
56
60
}
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ import (
35
35
"google.golang.org/grpc/grpclog"
36
36
"google.golang.org/grpc/internal/googlecloud"
37
37
internalgrpclog "google.golang.org/grpc/internal/grpclog"
38
+ "google.golang.org/grpc/internal/grpcrand"
38
39
"google.golang.org/grpc/internal/xds/env"
39
40
"google.golang.org/grpc/resolver"
40
41
_ "google.golang.org/grpc/xds" // To register xds resolvers and balancers.
@@ -152,13 +153,15 @@ var ipv6EnabledMetadata = &structpb.Struct{
152
153
},
153
154
}
154
155
156
+ var id = fmt .Sprintf ("C2P-%d" , grpcrand .Int ())
157
+
155
158
// newNode makes a copy of defaultNode, and populate it's Metadata and
156
159
// Locality fields.
157
160
func newNode (zone string , ipv6Capable bool ) * v3corepb.Node {
158
161
ret := & v3corepb.Node {
159
162
// Not all required fields are set in defaultNote. Metadata will be set
160
163
// if ipv6 is enabled. Locality will be set to the value from metadata.
161
- Id : "C2P" ,
164
+ Id : id ,
162
165
UserAgentName : gRPCUserAgentName ,
163
166
UserAgentVersionType : & v3corepb.Node_UserAgentVersion {UserAgentVersion : grpc .Version },
164
167
ClientFeatures : []string {clientFeatureNoOverprovisioning },
Original file line number Diff line number Diff line change @@ -194,7 +194,7 @@ func TestBuildXDS(t *testing.T) {
194
194
}
195
195
196
196
wantNode := & v3corepb.Node {
197
- Id : "C2P" ,
197
+ Id : id ,
198
198
Metadata : nil ,
199
199
Locality : & v3corepb.Locality {Zone : testZone },
200
200
UserAgentName : gRPCUserAgentName ,
You can’t perform that action at this time.
0 commit comments