add a counters.ZeroAll helper method for tests

Unlike ResetAll, ZeroAll keeps all the same keys in the map but
changes all the values to zero.

Signed-off-by: Michael Demmer <mdemmer@slack-corp.com>
This commit is contained in:
Michael Demmer 2018-05-20 21:41:06 -07:00
Родитель 3b8a3d5029
Коммит 67a94906ab
1 изменённых файлов: 10 добавлений и 1 удалений

Просмотреть файл

@ -88,13 +88,22 @@ func (c *counters) Add(name string, value int64) {
atomic.AddInt64(a, value)
}
// ResetAll resets all counter values.
// ResetAll resets all counter values and clears all keys.
func (c *counters) ResetAll() {
c.mu.Lock()
defer c.mu.Unlock()
c.counts = make(map[string]*int64)
}
// ZeroAll resets all counter values to zero
func (c *counters) ZeroAll() {
c.mu.Lock()
defer c.mu.Unlock()
for _, a := range c.counts {
atomic.StoreInt64(a, int64(0))
}
}
// Reset resets a specific counter value to 0.
func (c *counters) Reset(name string) {
a := c.getValueAddr(name)