Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
cc4910dd
Commit
cc4910dd
authored
Jan 12, 2026
by
shaw
Browse files
fix(test): 修复聚合测试的时区边界条件问题
parent
50de5d05
Changes
1
Show whitespace changes
Inline
Side-by-side
backend/internal/repository/usage_log_repo_integration_test.go
View file @
cc4910dd
...
...
@@ -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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment