Skip to content

Commit 7313692

Browse files
committed
add test verifications
1 parent 76099c8 commit 7313692

File tree

2 files changed

+110
-6
lines changed

2 files changed

+110
-6
lines changed

xds/internal/clients/lrsclient/loadreport_test.go

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (s) TestReportLoad_ConnectionCreation(t *testing.T) {
159159
t.Fatal("Timeout when waiting for LRS stream to be created")
160160
}
161161

162-
// Call the load reporting API to report load to the first management
162+
// Call the load reporting API to report load to the second management
163163
// server, and ensure that a connection to the server is created.
164164
serverIdentifier2 := clients.ServerIdentifier{ServerURI: mgmtServer2.Address, Extensions: grpctransport.ServerIdentifierExtension{ConfigName: "insecure"}}
165165
loadStore2, err := client.ReportLoad(serverIdentifier2)
@@ -199,10 +199,11 @@ func (s) TestReportLoad_ConnectionCreation(t *testing.T) {
199199
}
200200

201201
// Send a response from the server with a small deadline.
202+
serverReportInterval := 50 * time.Millisecond
202203
lrsServer.LRSResponseChan <- &fakeserver.Response{
203204
Resp: &v3lrspb.LoadStatsResponse{
204205
SendAllClusters: true,
205-
LoadReportingInterval: &durationpb.Duration{Nanos: 50000000}, // 50ms
206+
LoadReportingInterval: &durationpb.Duration{Nanos: int32(serverReportInterval.Nanoseconds())}, // 50ms
206207
},
207208
}
208209

@@ -216,6 +217,19 @@ func (s) TestReportLoad_ConnectionCreation(t *testing.T) {
216217
t.Fatalf("Received load for %d clusters, want 1", l)
217218
}
218219

220+
// Verify that LoadReportInterval for the first load report is positive but
221+
// not excessively large.
222+
//
223+
// Max expected: serverReportInterval + tolerance (e.g., 500ms).
224+
firstLoadReportInterval := gotLoad[0].GetLoadReportInterval().AsDuration()
225+
if firstLoadReportInterval <= 0 {
226+
t.Fatalf("First LoadReportInterval = %v, want > 0", firstLoadReportInterval)
227+
}
228+
tolerance := 500 * time.Millisecond
229+
if firstLoadReportInterval > serverReportInterval+tolerance {
230+
t.Errorf("First LoadReportInterval is unexpectedly large: %v", firstLoadReportInterval)
231+
}
232+
219233
// This field is set by the client to indicate the actual time elapsed since
220234
// the last report was sent. We cannot deterministically compare this, and
221235
// we cannot use the cmpopts.IgnoreFields() option on proto structs, since
@@ -324,10 +338,11 @@ func (s) TestReportLoad_StreamCreation(t *testing.T) {
324338
}
325339

326340
// Send a response from the server with a small deadline.
341+
serverReportInterval := 50 * time.Millisecond
327342
lrsServer.LRSResponseChan <- &fakeserver.Response{
328343
Resp: &v3lrspb.LoadStatsResponse{
329344
SendAllClusters: true,
330-
LoadReportingInterval: &durationpb.Duration{Nanos: 50000000}, // 50ms
345+
LoadReportingInterval: &durationpb.Duration{Nanos: int32(serverReportInterval.Nanoseconds())}, // 50ms
331346
},
332347
}
333348

@@ -341,6 +356,19 @@ func (s) TestReportLoad_StreamCreation(t *testing.T) {
341356
t.Fatalf("Received load for %d clusters, want 1", l)
342357
}
343358

359+
// Verify that LoadReportInterval for the first load report is positive but
360+
// not excessively large.
361+
//
362+
// Max expected: serverReportInterval + tolerance (e.g., 500ms).
363+
firstLoadReportInterval := gotLoad[0].GetLoadReportInterval().AsDuration()
364+
if firstLoadReportInterval <= 0 {
365+
t.Fatalf("First LoadReportInterval for cluster1 = %v, want > 0", firstLoadReportInterval)
366+
}
367+
tolerance := 500 * time.Millisecond
368+
if firstLoadReportInterval > serverReportInterval+tolerance {
369+
t.Errorf("First LoadReportInterval for cluster1 is unexpectedly large: %v", firstLoadReportInterval)
370+
}
371+
344372
// This field is set by the client to indicate the actual time elapsed since
345373
// the last report was sent. We cannot deterministically compare this, and
346374
// we cannot use the cmpopts.IgnoreFields() option on proto structs, since
@@ -406,6 +434,17 @@ func (s) TestReportLoad_StreamCreation(t *testing.T) {
406434
if l := len(gotLoad); l != 1 {
407435
continue
408436
}
437+
// Verify that LoadReportInterval for the subsequent load reports is
438+
// positive but not excessively large.
439+
//
440+
// Max expected: serverReportInterval + tolerance (e.g., 500ms).
441+
loadReportInterval := gotLoad[0].GetLoadReportInterval().AsDuration()
442+
if loadReportInterval <= 0 {
443+
t.Fatalf("LoadReportInterval = %v, want > 0", firstLoadReportInterval)
444+
}
445+
if loadReportInterval > serverReportInterval+tolerance {
446+
t.Errorf("LoadReportInterval is unexpectedly large: %v", loadReportInterval)
447+
}
409448
gotLoad[0].LoadReportInterval = nil
410449
wantLoad := &v3endpointpb.ClusterStats{
411450
ClusterName: "cluster2",
@@ -512,10 +551,11 @@ func (s) TestReportLoad_StopWithContext(t *testing.T) {
512551
}
513552

514553
// Send a response from the server with a small deadline.
554+
serverReportInterval := 50 * time.Millisecond
515555
lrsServer.LRSResponseChan <- &fakeserver.Response{
516556
Resp: &v3lrspb.LoadStatsResponse{
517557
SendAllClusters: true,
518-
LoadReportingInterval: &durationpb.Duration{Nanos: 50000000}, // 50ms
558+
LoadReportingInterval: &durationpb.Duration{Nanos: int32(serverReportInterval.Nanoseconds())}, // 50ms
519559
},
520560
}
521561

@@ -529,6 +569,19 @@ func (s) TestReportLoad_StopWithContext(t *testing.T) {
529569
t.Fatalf("Received load for %d clusters, want 1", l)
530570
}
531571

572+
// Verify that LoadReportInterval for the first load report is positive but
573+
// not excessively large.
574+
//
575+
// Max expected: serverReportInterval + tolerance (e.g., 500ms).
576+
firstLoadReportInterval := gotLoad[0].GetLoadReportInterval().AsDuration()
577+
if firstLoadReportInterval <= 0 {
578+
t.Fatalf("First LoadReportInterval = %v, want > 0", firstLoadReportInterval)
579+
}
580+
tolerance := 500 * time.Millisecond
581+
if firstLoadReportInterval > serverReportInterval+tolerance {
582+
t.Errorf("First LoadReportInterval is unexpectedly large: %v", firstLoadReportInterval)
583+
}
584+
532585
// This field is set by the client to indicate the actual time elapsed since
533586
// the last report was sent. We cannot deterministically compare this, and
534587
// we cannot use the cmpopts.IgnoreFields() option on proto structs, since
@@ -591,6 +644,17 @@ func (s) TestReportLoad_StopWithContext(t *testing.T) {
591644
if l := len(gotLoad); l != 1 {
592645
continue
593646
}
647+
// Verify that LoadReportInterval for the subsequent load reports is
648+
// positive but not excessively large.
649+
//
650+
// Max expected: serverReportInterval + tolerance (e.g., 500ms).
651+
loadReportInterval := gotLoad[0].GetLoadReportInterval().AsDuration()
652+
if loadReportInterval <= 0 {
653+
t.Fatalf("LoadReportInterval = %v, want > 0", firstLoadReportInterval)
654+
}
655+
if loadReportInterval > serverReportInterval+tolerance {
656+
t.Errorf("LoadReportInterval is unexpectedly large: %v", loadReportInterval)
657+
}
594658
gotLoad[0].LoadReportInterval = nil
595659
wantLoad := &v3endpointpb.ClusterStats{
596660
ClusterName: "cluster2",

xds/internal/xdsclient/tests/loadreport_test.go

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"fmt"
2525
"net"
2626
"testing"
27+
"time"
2728

2829
"github.com/google/go-cmp/cmp"
2930
"github.com/google/go-cmp/cmp/cmpopts"
@@ -192,10 +193,11 @@ func (s) TestReportLoad_ConnectionCreation(t *testing.T) {
192193
}
193194

194195
// Send a response from the server with a small deadline.
196+
serverReportInterval := 50 * time.Millisecond
195197
lrsServer.LRSResponseChan <- &fakeserver.Response{
196198
Resp: &v3lrspb.LoadStatsResponse{
197199
SendAllClusters: true,
198-
LoadReportingInterval: &durationpb.Duration{Nanos: 50000000}, // 50ms
200+
LoadReportingInterval: &durationpb.Duration{Nanos: int32(serverReportInterval.Nanoseconds())}, // 50ms
199201
},
200202
}
201203

@@ -209,6 +211,19 @@ func (s) TestReportLoad_ConnectionCreation(t *testing.T) {
209211
t.Fatalf("Received load for %d clusters, want 1", l)
210212
}
211213

214+
// Verify that LoadReportInterval for the first load report is positive but
215+
// not excessively large.
216+
//
217+
// Max expected: serverReportInterval + tolerance (e.g., 500ms).
218+
firstLoadReportInterval := gotLoad[0].GetLoadReportInterval().AsDuration()
219+
if firstLoadReportInterval <= 0 {
220+
t.Fatalf("First LoadReportInterval for cluster1 = %v, want > 0", firstLoadReportInterval)
221+
}
222+
tolerance := 500 * time.Millisecond
223+
if firstLoadReportInterval > serverReportInterval+tolerance {
224+
t.Errorf("First LoadReportInterval for cluster1 is unexpectedly large: %v", firstLoadReportInterval)
225+
}
226+
212227
// This field is set by the client to indicate the actual time elapsed since
213228
// the last report was sent. We cannot deterministically compare this, and
214229
// we cannot use the cmpopts.IgnoreFields() option on proto structs, since
@@ -307,10 +322,11 @@ func (s) TestReportLoad_StreamCreation(t *testing.T) {
307322
}
308323

309324
// Send a response from the server with a small deadline.
325+
serverReportInterval := 50 * time.Millisecond
310326
lrsServer.LRSResponseChan <- &fakeserver.Response{
311327
Resp: &v3lrspb.LoadStatsResponse{
312328
SendAllClusters: true,
313-
LoadReportingInterval: &durationpb.Duration{Nanos: 50000000}, // 50ms
329+
LoadReportingInterval: &durationpb.Duration{Nanos: int32(serverReportInterval.Nanoseconds())}, // 50ms
314330
},
315331
}
316332

@@ -324,6 +340,19 @@ func (s) TestReportLoad_StreamCreation(t *testing.T) {
324340
t.Fatalf("Received load for %d clusters, want 1", l)
325341
}
326342

343+
// Verify that LoadReportInterval for the first load report is positive but
344+
// not excessively large.
345+
//
346+
// Max expected: serverReportInterval + tolerance (e.g., 500ms).
347+
firstLoadReportInterval := gotLoad[0].GetLoadReportInterval().AsDuration()
348+
if firstLoadReportInterval <= 0 {
349+
t.Fatalf("First LoadReportInterval for cluster1 = %v, want > 0", firstLoadReportInterval)
350+
}
351+
tolerance := 500 * time.Millisecond
352+
if firstLoadReportInterval > serverReportInterval+tolerance {
353+
t.Errorf("First LoadReportInterval for cluster1 is unexpectedly large: %v", firstLoadReportInterval)
354+
}
355+
327356
// This field is set by the client to indicate the actual time elapsed since
328357
// the last report was sent. We cannot deterministically compare this, and
329358
// we cannot use the cmpopts.IgnoreFields() option on proto structs, since
@@ -386,6 +415,17 @@ func (s) TestReportLoad_StreamCreation(t *testing.T) {
386415
if l := len(gotLoad); l != 1 {
387416
continue
388417
}
418+
// Verify that LoadReportInterval for the subsequent load reports is
419+
// positive but not excessively large.
420+
//
421+
// Max expected: serverReportInterval + tolerance (e.g., 500ms).
422+
loadReportInterval := gotLoad[0].GetLoadReportInterval().AsDuration()
423+
if loadReportInterval <= 0 {
424+
t.Fatalf("LoadReportInterval = %v, want > 0", firstLoadReportInterval)
425+
}
426+
if loadReportInterval > serverReportInterval+tolerance {
427+
t.Errorf("LoadReportInterval is unexpectedly large: %v", loadReportInterval)
428+
}
389429
gotLoad[0].LoadReportInterval = nil
390430
wantLoad := &v3endpointpb.ClusterStats{
391431
ClusterName: "cluster2",

0 commit comments

Comments
 (0)