git/githistory/log: panic() when *PercentageTask is over-counted
This commit is contained in:
parent
78195ec383
commit
b51003e648
@ -38,7 +38,9 @@ func NewPercentageTask(msg string, total uint64) *PercentageTask {
|
||||
// Count returns the new total number of (atomically managed) elements that have
|
||||
// been completed.
|
||||
func (c *PercentageTask) Count(n uint64) (new uint64) {
|
||||
new = atomic.AddUint64(&c.n, n)
|
||||
if new = atomic.AddUint64(&c.n, n); new > c.total {
|
||||
panic("git/githistory/log: counted too many items")
|
||||
}
|
||||
|
||||
var percentage float64
|
||||
if c.total == 0 {
|
||||
|
@ -60,3 +60,12 @@ func TestPercentageTaskIsThrottled(t *testing.T) {
|
||||
assert.True(t, throttled,
|
||||
"git/githistory/log: expected *PercentageTask to be Throttle()-d")
|
||||
}
|
||||
|
||||
func TestPercentageTaskPanicsWhenOvercounted(t *testing.T) {
|
||||
task := NewPercentageTask("example", 0)
|
||||
defer func() {
|
||||
assert.Equal(t, "git/githistory/log: counted too many items", recover())
|
||||
}()
|
||||
|
||||
task.Count(1)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user