@@ -154,6 +154,22 @@ func TestGCCPULimiter(t *testing.T) {
154154 // Drain the bucket by half.
155155 l .AddAssistTime (assistTime (CapacityPerProc , 0 ))
156156 l .Update (advance (CapacityPerProc ))
157+ //
158+ // test start condition: l.Fill == l.Capacity
159+ //
160+ // assistTime = 0
161+ // gcTime = CapacityPerProc * procs * GCBackgroundUtilization
162+ // mutatorTime = CapacityPerProc * procs * (1 - GCBackgroundUtilization)
163+ // change = gcTime - mutatorTime
164+ // = CapacityPerProc * procs * (2 * GCBackgroundUtilization - 1)
165+ // l.Fill = l.Fill + change // here change < 0
166+ // = l.Capacity + change
167+ // = CapacityPerProc * procs + change
168+ // = CapacityPerProc * procs * 2 * GCBackgroundUtilization
169+ // = l.Capacity * 2 * GCBackgroundUtilization
170+ // = l.Capacity * 0.5 // by default GCBackgroundUtilization = 0.25
171+ // = l.Capacity / 2
172+ //
157173 if expect := l .Capacity () / 2 ; l .Fill () != expect {
158174 t .Errorf ("failed to drain to %d, got fill %d" , expect , l .Fill ())
159175 }
@@ -167,6 +183,25 @@ func TestGCCPULimiter(t *testing.T) {
167183 // Test overfilling the bucket.
168184 l .AddAssistTime (assistTime (CapacityPerProc , 1.0 - GCBackgroundUtilization ))
169185 l .Update (advance (CapacityPerProc ))
186+ //
187+ // test start condition: l.Fill == l.Capacity * 2 * GCBackgroundUtilization
188+ //
189+ // assistTime = CapacityPerProc * procs * (1 - GCBackgroundUtilization)
190+ // gcTime = CapacityPerProc * procs * GCBackgroundUtilization + assistTime
191+ // = CapacityPerProc * procs
192+ // = l.Capacity
193+ // mutatorTime = CapacityPerProc * procs * (1 - GCBackgroundUtilization) - assistTime
194+ // = 0
195+ // change = gcTime - mutatorTime
196+ // = l.Capacity
197+ // l.Overflow = l.Fill + change - l.Capacity
198+ // = l.Capacity * 2 * GCBackgroundUtilization + l.Capacity - l.Capacity
199+ // = l.Capacity * 2 * GCBackgroundUtilization
200+ // = l.Capacity * 0.5 // by default GCBackgroundUtilization = 0.25
201+ // = l.Capacity / 2
202+ // = CapacityPerProc * procs / 2
203+ // l.Fill = l.Capacity // because change is too large
204+ //
170205 if l .Fill () != l .Capacity () {
171206 t .Errorf ("failed to fill to capacity %d, got fill %d" , l .Capacity (), l .Fill ())
172207 }
0 commit comments