@@ -96,13 +96,22 @@ func enforcesBudget(t *testing.T, busyloopPath string) {
9696 require .NoError (t , err )
9797 }
9898
99- // Check that throttling happened.
100- perCoreStats := program . RuntimeStats ( )
99+ // Check that throttling happened. We may need to give it more time.
100+ deadline := time . Now (). Add ( 5 * time . Second )
101101 var stats loader.RuntimeStats
102- for _ , coreStats := range perCoreStats {
103- stats .HitCnt += coreStats .HitCnt
104- stats .ThrottledCnt += coreStats .ThrottledCnt
105- stats .CPU += coreStats .CPU
102+ for {
103+ stats = loader.RuntimeStats {}
104+ perCoreStats := program .RuntimeStats ()
105+ for _ , coreStats := range perCoreStats {
106+ stats .HitCnt += coreStats .HitCnt
107+ stats .ThrottledCnt += coreStats .ThrottledCnt
108+ stats .CPU += coreStats .CPU
109+ }
110+ if int (stats .ThrottledCnt ) > 0 {
111+ break
112+ }
113+ require .True (t , time .Now ().Before (deadline ), "timed out waiting for throttling to happen" )
114+ time .Sleep (100 * time .Millisecond )
106115 }
107116 require .Greater (t , int (stats .HitCnt ), expectedEvents )
108117 require .Greater (t , int (stats .ThrottledCnt ), 0 )
0 commit comments