Fix race in safesearch tests

This commit is contained in:
Andrey Meshkov
2019-02-25 18:56:51 +03:00
parent 77348e746f
commit c71d6ed433
4 changed files with 26 additions and 12 deletions

View File

@@ -61,9 +61,11 @@ func newStats() *stats {
}
func initPeriodicStats(periodic *periodicStats, period time.Duration) {
periodic.Lock()
periodic.entries = statsEntries{}
periodic.lastRotate = time.Now()
periodic.period = period
periodic.Unlock()
}
func (s *stats) purgeStats() {
@@ -253,6 +255,9 @@ func (s *stats) getAggregatedStats() map[string]interface{} {
}
func (s *stats) generateMapFromStats(stats *periodicStats, start int, end int) map[string]interface{} {
stats.RLock()
defer stats.RUnlock()
// clamp
start = clamp(start, 0, statsHistoryElements)
end = clamp(end, 0, statsHistoryElements)