@@ -331,9 +331,10 @@ func runThrottler(t *testing.T, throttler *Throttler, timeout time.Duration, f f
331
331
assert .True (t , throttler .IsOpen ())
332
332
assert .False (t , throttler .IsEnabled ())
333
333
334
- ok := throttler .Enable ()
334
+ wg := throttler .Enable ()
335
335
defer throttler .Disable ()
336
- assert .True (t , ok )
336
+ assert .NotNil (t , wg )
337
+ defer wg .Wait ()
337
338
assert .True (t , throttler .IsEnabled ())
338
339
339
340
if f != nil {
@@ -382,3 +383,52 @@ func TestProbesWhileOperating(t *testing.T) {
382
383
})
383
384
})
384
385
}
386
+
387
+ // TestProbesPostDisable runs the throttler for some time, and then investigates the internal throttler maps and values.
388
+ // While the throttler is disabled, it is technically safe to iterate those structures. However, `go test -race` disagrees,
389
+ // which is why this test is in this *exclude_race* file
390
+ func TestProbesPostDisable (t * testing.T ) {
391
+ throttler := newTestThrottler ()
392
+ runThrottler (t , throttler , 2 * time .Second , nil )
393
+
394
+ time .Sleep (time .Second ) // throttler's Operate() quits asynchronously. For sake of `go test -race` we allow a graceful wait.
395
+ probes := throttler .mysqlInventory .ClustersProbes
396
+ assert .NotEmpty (t , probes )
397
+
398
+ selfProbes := probes [selfStoreName ]
399
+ t .Run ("self" , func (t * testing.T ) {
400
+ assert .NotEmpty (t , selfProbes )
401
+ require .Equal (t , 1 , len (selfProbes )) // should always be true once refreshMySQLInventory() runs
402
+ probe , ok := selfProbes ["" ]
403
+ assert .True (t , ok )
404
+ assert .NotNil (t , probe )
405
+
406
+ assert .Equal (t , "" , probe .Alias )
407
+ assert .Nil (t , probe .Tablet )
408
+ assert .Equal (t , "select 1" , probe .MetricQuery )
409
+ assert .Zero (t , atomic .LoadInt64 (& probe .QueryInProgress ))
410
+ })
411
+
412
+ shardProbes := probes [shardStoreName ]
413
+ t .Run ("shard" , func (t * testing.T ) {
414
+ assert .NotEmpty (t , shardProbes )
415
+ assert .Equal (t , 2 , len (shardProbes )) // see fake FindAllTabletAliasesInShard above
416
+ for _ , probe := range shardProbes {
417
+ require .NotNil (t , probe )
418
+ assert .NotEmpty (t , probe .Alias )
419
+ assert .NotNil (t , probe .Tablet )
420
+ assert .Equal (t , "select 1" , probe .MetricQuery )
421
+ assert .Zero (t , atomic .LoadInt64 (& probe .QueryInProgress ))
422
+ }
423
+ })
424
+
425
+ t .Run ("metrics" , func (t * testing.T ) {
426
+ assert .Equal (t , 3 , len (throttler .mysqlInventory .TabletMetrics )) // 1 self tablet + 2 shard tablets
427
+ })
428
+
429
+ t .Run ("aggregated" , func (t * testing.T ) {
430
+ assert .Zero (t , throttler .aggregatedMetrics .ItemCount ()) // flushed upon Disable()
431
+ aggr := throttler .aggregatedMetricsSnapshot ()
432
+ assert .Empty (t , aggr )
433
+ })
434
+ }
0 commit comments