fix off by one err in current month client count computation (#17457)
This commit is contained in:
parent
fdb13d7481
commit
2c9b29ab42
|
@ -74,7 +74,7 @@ func (a *ActivityLog) computeCurrentMonthForBillingPeriodInternal(ctx context.Co
|
|||
if len(monthlyComputation) > 1 {
|
||||
a.logger.Warn("monthly in-memory activitylog computation returned multiple months of data", "months returned", len(byMonth))
|
||||
}
|
||||
if len(monthlyComputation) >= 0 {
|
||||
if len(monthlyComputation) > 0 {
|
||||
return monthlyComputation[0], nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,4 +125,28 @@ func Test_ActivityLog_ComputeCurrentMonthForBillingPeriodInternal(t *testing.T)
|
|||
if monthRecord.NewClients.Counts.NonEntityClients != 4 {
|
||||
t.Fatalf("wrong number of new non entity clients. Expected 4, got %d", monthRecord.NewClients.Counts.NonEntityClients)
|
||||
}
|
||||
|
||||
// Attempt to compute current month when no records exist
|
||||
endTime = time.Now().UTC()
|
||||
startTime = timeutil.StartOfMonth(endTime)
|
||||
emptyClientsMap := make(map[int64]*processMonth, 0)
|
||||
monthRecord, err = a.computeCurrentMonthForBillingPeriodInternal(context.Background(), emptyClientsMap, mockHLLGetFunc, startTime, endTime)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to compute empty current month, err: %v", err)
|
||||
}
|
||||
|
||||
// We should have 0 entity clients, nonentity clients,new entity clients
|
||||
// and new nonentity clients
|
||||
if monthRecord.Counts.EntityClients != 0 {
|
||||
t.Fatalf("wrong number of entity clients. Expected 0, got %d", monthRecord.Counts.EntityClients)
|
||||
}
|
||||
if monthRecord.Counts.NonEntityClients != 0 {
|
||||
t.Fatalf("wrong number of non entity clients. Expected 0, got %d", monthRecord.Counts.NonEntityClients)
|
||||
}
|
||||
if monthRecord.NewClients.Counts.EntityClients != 0 {
|
||||
t.Fatalf("wrong number of new entity clients. Expected 0, got %d", monthRecord.NewClients.Counts.EntityClients)
|
||||
}
|
||||
if monthRecord.NewClients.Counts.NonEntityClients != 0 {
|
||||
t.Fatalf("wrong number of new non entity clients. Expected 0, got %d", monthRecord.NewClients.Counts.NonEntityClients)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue