- stats: fix crash

This commit is contained in:
Simon Zolin 2019-10-09 17:17:57 +03:00
parent f4451dca7b
commit 9ff39a362f
2 changed files with 32 additions and 4 deletions

View File

@ -124,3 +124,31 @@ func TestLargeNumbers(t *testing.T) {
s.Close()
os.Remove(conf.Filename)
}
// this code is a chunk copied from getData() that generates aggregate data per day
func aggregateDataPerDay(firstID uint32) int {
firstDayID := (firstID + 24 - 1) / 24 * 24 // align_ceil(24)
a := []uint64{}
var sum uint64
id := firstDayID
nextDayID := firstDayID + 24
for i := firstDayID - firstID; int(i) != 720; i++ {
sum++
if id == nextDayID {
a = append(a, sum)
sum = 0
nextDayID += 24
}
id++
}
if id <= nextDayID {
a = append(a, sum)
}
return len(a)
}
func TestAggregateDataPerTimeUnit(t *testing.T) {
for i := 0; i != 25; i++ {
alen := aggregateDataPerDay(uint32(i))
assert.True(t, alen == 30, "i=%d", i)
}
}

View File

@ -551,7 +551,7 @@ func (s *statsCtx) getData(timeUnit TimeUnit) map[string]interface{} {
}
id++
}
if id < nextDayID {
if id <= nextDayID {
a = append(a, sum)
}
if len(a) != int(s.limit/24) {
@ -578,7 +578,7 @@ func (s *statsCtx) getData(timeUnit TimeUnit) map[string]interface{} {
}
id++
}
if id < nextDayID {
if id <= nextDayID {
a = append(a, sum)
}
}
@ -602,7 +602,7 @@ func (s *statsCtx) getData(timeUnit TimeUnit) map[string]interface{} {
}
id++
}
if id < nextDayID {
if id <= nextDayID {
a = append(a, sum)
}
}
@ -626,7 +626,7 @@ func (s *statsCtx) getData(timeUnit TimeUnit) map[string]interface{} {
}
id++
}
if id < nextDayID {
if id <= nextDayID {
a = append(a, sum)
}
}