@@ -159,7 +159,7 @@ func (s) TestReportLoad_ConnectionCreation(t *testing.T) {
159
159
t .Fatal ("Timeout when waiting for LRS stream to be created" )
160
160
}
161
161
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
163
163
// server, and ensure that a connection to the server is created.
164
164
serverIdentifier2 := clients.ServerIdentifier {ServerURI : mgmtServer2 .Address , Extensions : grpctransport.ServerIdentifierExtension {ConfigName : "insecure" }}
165
165
loadStore2 , err := client .ReportLoad (serverIdentifier2 )
@@ -199,10 +199,11 @@ func (s) TestReportLoad_ConnectionCreation(t *testing.T) {
199
199
}
200
200
201
201
// Send a response from the server with a small deadline.
202
+ serverReportInterval := 50 * time .Millisecond
202
203
lrsServer .LRSResponseChan <- & fakeserver.Response {
203
204
Resp : & v3lrspb.LoadStatsResponse {
204
205
SendAllClusters : true ,
205
- LoadReportingInterval : & durationpb.Duration {Nanos : 50000000 }, // 50ms
206
+ LoadReportingInterval : & durationpb.Duration {Nanos : int32 ( serverReportInterval . Nanoseconds ()) }, // 50ms
206
207
},
207
208
}
208
209
@@ -216,6 +217,19 @@ func (s) TestReportLoad_ConnectionCreation(t *testing.T) {
216
217
t .Fatalf ("Received load for %d clusters, want 1" , l )
217
218
}
218
219
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
+
219
233
// This field is set by the client to indicate the actual time elapsed since
220
234
// the last report was sent. We cannot deterministically compare this, and
221
235
// we cannot use the cmpopts.IgnoreFields() option on proto structs, since
@@ -324,10 +338,11 @@ func (s) TestReportLoad_StreamCreation(t *testing.T) {
324
338
}
325
339
326
340
// Send a response from the server with a small deadline.
341
+ serverReportInterval := 50 * time .Millisecond
327
342
lrsServer .LRSResponseChan <- & fakeserver.Response {
328
343
Resp : & v3lrspb.LoadStatsResponse {
329
344
SendAllClusters : true ,
330
- LoadReportingInterval : & durationpb.Duration {Nanos : 50000000 }, // 50ms
345
+ LoadReportingInterval : & durationpb.Duration {Nanos : int32 ( serverReportInterval . Nanoseconds ()) }, // 50ms
331
346
},
332
347
}
333
348
@@ -341,6 +356,19 @@ func (s) TestReportLoad_StreamCreation(t *testing.T) {
341
356
t .Fatalf ("Received load for %d clusters, want 1" , l )
342
357
}
343
358
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
+
344
372
// This field is set by the client to indicate the actual time elapsed since
345
373
// the last report was sent. We cannot deterministically compare this, and
346
374
// we cannot use the cmpopts.IgnoreFields() option on proto structs, since
@@ -406,6 +434,17 @@ func (s) TestReportLoad_StreamCreation(t *testing.T) {
406
434
if l := len (gotLoad ); l != 1 {
407
435
continue
408
436
}
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
+ }
409
448
gotLoad [0 ].LoadReportInterval = nil
410
449
wantLoad := & v3endpointpb.ClusterStats {
411
450
ClusterName : "cluster2" ,
@@ -512,10 +551,11 @@ func (s) TestReportLoad_StopWithContext(t *testing.T) {
512
551
}
513
552
514
553
// Send a response from the server with a small deadline.
554
+ serverReportInterval := 50 * time .Millisecond
515
555
lrsServer .LRSResponseChan <- & fakeserver.Response {
516
556
Resp : & v3lrspb.LoadStatsResponse {
517
557
SendAllClusters : true ,
518
- LoadReportingInterval : & durationpb.Duration {Nanos : 50000000 }, // 50ms
558
+ LoadReportingInterval : & durationpb.Duration {Nanos : int32 ( serverReportInterval . Nanoseconds ()) }, // 50ms
519
559
},
520
560
}
521
561
@@ -529,6 +569,19 @@ func (s) TestReportLoad_StopWithContext(t *testing.T) {
529
569
t .Fatalf ("Received load for %d clusters, want 1" , l )
530
570
}
531
571
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
+
532
585
// This field is set by the client to indicate the actual time elapsed since
533
586
// the last report was sent. We cannot deterministically compare this, and
534
587
// we cannot use the cmpopts.IgnoreFields() option on proto structs, since
@@ -591,6 +644,17 @@ func (s) TestReportLoad_StopWithContext(t *testing.T) {
591
644
if l := len (gotLoad ); l != 1 {
592
645
continue
593
646
}
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
+ }
594
658
gotLoad [0 ].LoadReportInterval = nil
595
659
wantLoad := & v3endpointpb.ClusterStats {
596
660
ClusterName : "cluster2" ,
0 commit comments