@@ -39,6 +39,13 @@ type rpcData struct {
39
39
serverData map [string ]float64 // Will be reported with successful RPCs.
40
40
}
41
41
42
+ func verifyLoadStoreData (wantStoreData , gotStoreData []* loadData ) error {
43
+ if diff := cmp .Diff (wantStoreData , gotStoreData , cmpopts .EquateEmpty (), cmp .AllowUnexported (loadData {}, localityData {}, requestData {}, serverLoadData {}), cmpopts .IgnoreFields (loadData {}, "reportInterval" ), sortDataSlice ); diff != "" {
44
+ return fmt .Errorf ("store.stats() returned unexpected diff (-want +got):\n %s" , diff )
45
+ }
46
+ return nil
47
+ }
48
+
42
49
// TestDrops spawns a bunch of goroutines which report drop data. After the
43
50
// goroutines have exited, the test dumps the stats from the Store and makes
44
51
// sure they are as expected.
@@ -72,8 +79,8 @@ func TestDrops(t *testing.T) {
72
79
wg .Wait ()
73
80
74
81
gotStoreData := ls .stats ()
75
- if diff := cmp . Diff ( wantStoreData , gotStoreData , cmpopts . EquateEmpty (), cmp . AllowUnexported ( loadData {}), cmpopts . IgnoreFields ( loadData {}, "reportInterval" )); diff != "" {
76
- t .Errorf ( "store.stats() returned unexpected diff (-want +got): \n %s" , diff )
82
+ if err := verifyLoadStoreData ([] * loadData {wantStoreData }, [] * loadData {gotStoreData }); err != nil {
83
+ t .Error ( err )
77
84
}
78
85
}
79
86
@@ -165,8 +172,8 @@ func TestLocalityStats(t *testing.T) {
165
172
}
166
173
167
174
gotStoreData := ls .stats ()
168
- if diff := cmp . Diff ( wantStoreData , gotStoreData , cmpopts . EquateEmpty (), cmp . AllowUnexported ( loadData {}, localityData {}, requestData {}, serverLoadData {}), cmpopts . IgnoreFields ( loadData {}, "reportInterval" )); diff != "" {
169
- t .Errorf ( "store.stats() returned unexpected diff (-want +got): \n %s" , diff )
175
+ if err := verifyLoadStoreData ([] * loadData {wantStoreData }, [] * loadData {gotStoreData }); err != nil {
176
+ t .Error ( err )
170
177
}
171
178
}
172
179
@@ -260,8 +267,8 @@ func TestResetAfterStats(t *testing.T) {
260
267
ls := PerClusterReporter {}
261
268
reportLoad (& ls )
262
269
gotStoreData := ls .stats ()
263
- if diff := cmp . Diff ( wantStoreData , gotStoreData , cmpopts . EquateEmpty (), cmp . AllowUnexported ( loadData {}, localityData {}, requestData {}, serverLoadData {}), cmpopts . IgnoreFields ( loadData {}, "reportInterval" )); diff != "" {
264
- t .Errorf ( "store.stats() returned unexpected diff (-want +got): \n %s" , diff )
270
+ if err := verifyLoadStoreData ([] * loadData {wantStoreData }, [] * loadData {gotStoreData }); err != nil {
271
+ t .Error ( err )
265
272
}
266
273
267
274
// The above call to stats() should have reset all load reports except the
@@ -274,8 +281,8 @@ func TestResetAfterStats(t *testing.T) {
274
281
}
275
282
reportLoad (& ls )
276
283
gotStoreData = ls .stats ()
277
- if diff := cmp . Diff ( wantStoreData , gotStoreData , cmpopts . EquateEmpty (), cmp . AllowUnexported ( loadData {}, localityData {}, requestData {}, serverLoadData {}), cmpopts . IgnoreFields ( loadData {}, "reportInterval" )); diff != "" {
278
- t .Errorf ( "store.stats() returned unexpected diff (-want +got): \n %s" , diff )
284
+ if err := verifyLoadStoreData ([] * loadData {wantStoreData }, [] * loadData {gotStoreData }); err != nil {
285
+ t .Error ( err )
279
286
}
280
287
}
281
288
@@ -304,7 +311,7 @@ func TestStoreStats(t *testing.T) {
304
311
testLocality = "test-locality"
305
312
)
306
313
307
- store := newLoadStore (nil )
314
+ store := newLoadStore ()
308
315
for _ , c := range testClusters {
309
316
for _ , s := range testServices {
310
317
store .ReporterForCluster (c , s ).CallStarted (testLocality )
@@ -339,9 +346,7 @@ func TestStoreStats(t *testing.T) {
339
346
// Call Stats with just "c0", this should return data for "c0", and not
340
347
// touch data for other clusters.
341
348
gotC0 := store .stats ([]string {"c0" })
342
- if diff := cmp .Diff (wantC0 , gotC0 , cmpopts .EquateEmpty (), cmp .AllowUnexported (loadData {}, localityData {}, requestData {}, serverLoadData {}), cmpopts .IgnoreFields (loadData {}, "reportInterval" ), sortDataSlice ); diff != "" {
343
- t .Errorf ("store.stats() returned unexpected diff (-want +got):\n %s" , diff )
344
- }
349
+ verifyLoadStoreData (wantC0 , gotC0 )
345
350
346
351
wantOther := []* loadData {
347
352
{
@@ -388,8 +393,8 @@ func TestStoreStats(t *testing.T) {
388
393
// Call Stats with empty slice, this should return data for all the
389
394
// remaining clusters, and not include c0 (because c0 data was cleared).
390
395
gotOther := store .stats (nil )
391
- if diff := cmp . Diff (wantOther , gotOther , cmpopts . EquateEmpty (), cmp . AllowUnexported ( loadData {}, localityData {}, requestData {}, serverLoadData {}), cmpopts . IgnoreFields ( loadData {}, "reportInterval" ), sortDataSlice ); diff != "" {
392
- t .Errorf ( "store.stats() returned unexpected diff (-want +got): \n %s" , diff )
396
+ if err := verifyLoadStoreData (wantOther , gotOther ); err != nil {
397
+ t .Error ( err )
393
398
}
394
399
}
395
400
@@ -401,7 +406,7 @@ func TestStoreStatsEmptyDataNotReported(t *testing.T) {
401
406
testLocality = "test-locality"
402
407
)
403
408
404
- store := newLoadStore (nil )
409
+ store := newLoadStore ()
405
410
// "c0"'s RPCs all finish with success.
406
411
for _ , s := range testServices {
407
412
store .ReporterForCluster ("c0" , s ).CallStarted (testLocality )
@@ -441,8 +446,8 @@ func TestStoreStatsEmptyDataNotReported(t *testing.T) {
441
446
// Call Stats with empty slice, this should return data for all the
442
447
// clusters.
443
448
got0 := store .stats (nil )
444
- if diff := cmp . Diff (want0 , got0 , cmpopts . EquateEmpty (), cmp . AllowUnexported ( loadData {}, localityData {}, requestData {}, serverLoadData {}), cmpopts . IgnoreFields ( loadData {}, "reportInterval" ), sortDataSlice ); diff != "" {
445
- t .Errorf ( "store.stats() returned unexpected diff (-want +got): \n %s" , diff )
449
+ if err := verifyLoadStoreData (want0 , got0 ); err != nil {
450
+ t .Error ( err )
446
451
}
447
452
448
453
want1 := []* loadData {
@@ -462,7 +467,7 @@ func TestStoreStatsEmptyDataNotReported(t *testing.T) {
462
467
// Call Stats with empty slice again, this should return data only for "c1",
463
468
// because "c0" data was cleared, but "c1" has in-progress RPCs.
464
469
got1 := store .stats (nil )
465
- if diff := cmp . Diff (want1 , got1 , cmpopts . EquateEmpty (), cmp . AllowUnexported ( loadData {}, localityData {}, requestData {}, serverLoadData {}), cmpopts . IgnoreFields ( loadData {}, "reportInterval" ), sortDataSlice ); diff != "" {
466
- t .Errorf ( "store.stats() returned unexpected diff (-want +got): \n %s" , diff )
470
+ if err := verifyLoadStoreData (want1 , got1 ); err != nil {
471
+ t .Error ( err )
467
472
}
468
473
}
0 commit comments