@@ -552,44 +552,61 @@ func TestUsageTracker_PartitionAssignment(t *testing.T) {
552552}
553553
554554func TestUsageTracker_GetUsersCloseToLimit (t * testing.T ) {
555- makeSeries := func (n int ) []uint64 {
556- series := make ([]uint64 , n )
557- for i := range series {
558- series [i ] = uint64 (i )
555+ t .Run ("happy case" , func (t * testing.T ) {
556+ makeSeries := func (n int ) []uint64 {
557+ series := make ([]uint64 , n )
558+ for i := range series {
559+ series [i ] = uint64 (i )
560+ }
561+ return series
559562 }
560- return series
561- }
562-
563- tracker := newReadyTestUsageTracker (t , map [string ]* validation.Limits {
564- "a" : {MaxActiveSeriesPerUser : 1000 * testPartitionsCount },
565- "b" : {MaxActiveSeriesPerUser : 2000 * testPartitionsCount },
566- "c" : {MaxActiveSeriesPerUser : 1000 * testPartitionsCount },
567- "d" : {MaxActiveSeriesPerUser : 2000 * testPartitionsCount },
568- "e" : {MaxActiveSeriesPerUser : 1000 * testPartitionsCount },
569- })
570563
571- for _ , tenant := range []string {"a" , "b" , "c" , "d" , "e" } {
572- resp , err := tracker .TrackSeries (t .Context (), & usagetrackerpb.TrackSeriesRequest {
573- UserID : tenant ,
574- Partition : 0 ,
575- SeriesHashes : makeSeries (900 ),
564+ tracker := newReadyTestUsageTracker (t , map [string ]* validation.Limits {
565+ "a" : {MaxActiveSeriesPerUser : 1000 * testPartitionsCount },
566+ "b" : {MaxActiveSeriesPerUser : 2000 * testPartitionsCount },
567+ "c" : {MaxActiveSeriesPerUser : 1000 * testPartitionsCount },
568+ "d" : {MaxActiveSeriesPerUser : 2000 * testPartitionsCount },
569+ "e" : {MaxActiveSeriesPerUser : 1000 * testPartitionsCount },
576570 })
577- require .NoError (t , err )
578- require .Empty (t , resp .RejectedSeriesHashes )
579- }
580571
581- // Call updateLimits (on all partitions, although we only need partition 0.
582- withRLock (& tracker .partitionsMtx , func () {
583- for _ , p := range tracker .partitions {
584- done := make (chan struct {})
585- p .forceUpdateLimitsForTests <- done
586- <- done
572+ for _ , tenant := range []string {"a" , "b" , "c" , "d" , "e" } {
573+ resp , err := tracker .TrackSeries (t .Context (), & usagetrackerpb.TrackSeriesRequest {
574+ UserID : tenant ,
575+ Partition : 0 ,
576+ SeriesHashes : makeSeries (900 ),
577+ })
578+ require .NoError (t , err )
579+ require .Empty (t , resp .RejectedSeriesHashes )
587580 }
581+
582+ // Call updateLimits (on all partitions, although we only need partition 0.
583+ withRLock (& tracker .partitionsMtx , func () {
584+ for _ , p := range tracker .partitions {
585+ done := make (chan struct {})
586+ p .forceUpdateLimitsForTests <- done
587+ <- done
588+ }
589+ })
590+
591+ resp , err := tracker .GetUsersCloseToLimit (t .Context (), & usagetrackerpb.GetUsersCloseToLimitRequest {Partition : 0 })
592+ require .NoError (t , err )
593+ require .Equal (t , []string {"a" , "c" , "e" }, resp .SortedUserIds , "List of users close to the limit should be sorted lexicographically" )
588594 })
589595
590- resp , err := tracker .GetUsersCloseToLimit (t .Context (), & usagetrackerpb.GetUsersCloseToLimitRequest {Partition : 0 })
591- require .NoError (t , err )
592- require .Equal (t , []string {"a" , "c" , "e" }, resp .SortedUserIds , "List of users close to the limit should be sorted lexicographically" )
596+ t .Run ("partition handler is not running" , func (t * testing.T ) {
597+ tracker := newReadyTestUsageTracker (t , map [string ]* validation.Limits {
598+ "a" : {MaxActiveSeriesPerUser : 1000 * testPartitionsCount },
599+ })
600+
601+ // Call updateLimits (on all partitions, although we only need partition 0.
602+ withRLock (& tracker .partitionsMtx , func () {
603+ require .NoError (t , services .StopAndAwaitTerminated (context .Background (), tracker .partitions [0 ]))
604+ })
605+
606+ _ , err := tracker .GetUsersCloseToLimit (t .Context (), & usagetrackerpb.GetUsersCloseToLimitRequest {Partition : 0 })
607+ require .Error (t , err )
608+ require .ErrorContains (t , err , "partition handler 0 is not running (state: Terminated)" )
609+ })
593610}
594611
595612func callPrepareDownscaleEndpoint (t * testing.T , ut * UsageTracker , method string ) {
0 commit comments