From cc4910dd30882cd32c76af81059bac579ad4b539 Mon Sep 17 00:00:00 2001 From: shaw Date: Mon, 12 Jan 2026 09:23:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(test):=20=E4=BF=AE=E5=A4=8D=E8=81=9A?= =?UTF-8?q?=E5=90=88=E6=B5=8B=E8=AF=95=E7=9A=84=E6=97=B6=E5=8C=BA=E8=BE=B9?= =?UTF-8?q?=E7=95=8C=E6=9D=A1=E4=BB=B6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/usage_log_repo_integration_test.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/backend/internal/repository/usage_log_repo_integration_test.go b/backend/internal/repository/usage_log_repo_integration_test.go index 591ee2f5..3f90e49e 100644 --- a/backend/internal/repository/usage_log_repo_integration_test.go +++ b/backend/internal/repository/usage_log_repo_integration_test.go @@ -413,9 +413,17 @@ func (s *UsageLogRepoSuite) TestGetAccountTodayStats() { func (s *UsageLogRepoSuite) TestDashboardAggregationConsistency() { now := time.Now().UTC().Truncate(time.Second) - hour1 := now.Add(-90 * time.Minute).Truncate(time.Hour) - hour2 := now.Add(-30 * time.Minute).Truncate(time.Hour) + // 使用固定的时间偏移确保 hour1 和 hour2 在同一天且都在过去 + // 选择当天 02:00 和 03:00 作为测试时间点(基于 now 的日期) dayStart := truncateToDayUTC(now) + hour1 := dayStart.Add(2 * time.Hour) // 当天 02:00 + hour2 := dayStart.Add(3 * time.Hour) // 当天 03:00 + // 如果当前时间早于 hour2,则使用昨天的时间 + if now.Before(hour2.Add(time.Hour)) { + dayStart = dayStart.Add(-24 * time.Hour) + hour1 = dayStart.Add(2 * time.Hour) + hour2 = dayStart.Add(3 * time.Hour) + } user1 := mustCreateUser(s.T(), s.client, &service.User{Email: "agg-u1@test.com"}) user2 := mustCreateUser(s.T(), s.client, &service.User{Email: "agg-u2@test.com"}) @@ -473,7 +481,7 @@ func (s *UsageLogRepoSuite) TestDashboardAggregationConsistency() { aggRepo := newDashboardAggregationRepositoryWithSQL(s.tx) aggStart := hour1.Add(-5 * time.Minute) - aggEnd := now.Add(5 * time.Minute) + aggEnd := hour2.Add(time.Hour) // 确保覆盖 hour2 的所有数据 s.Require().NoError(aggRepo.AggregateRange(s.ctx, aggStart, aggEnd)) type hourlyRow struct {