test(feed): 覆盖过期与未来 as_of 的替换

过期的 as_of 超出快照 TTL。服务端换回上一个闭合分钟,客户端据此重置分页。
未来的 as_of 属于仍未闭合的分钟。窗口还在增长,同样不能采纳。
验证:MYSQL_TEST_DSN=... go test -tags integration -count=1 -p 1 -run TestListByPopularity ./internal/feed/ 通过。
This commit is contained in:
2026-11-01 15:16:56 +08:00
parent bc1252e66c
commit 0fcbf3ae00

View File

@@ -268,3 +268,32 @@ func TestListByPopularity_SnapshotExpireFailureDropsKey(t *testing.T) {
t.Fatal("EXPIRE 失败必须删除快照键:留着它只活 1 分钟,客户端永远翻不到第 2 页")
}
}
// 过期的 as_of 与未来的 as_of 都不能被采纳。
//
// 前者:快照已过 TTL,重建出来是另一个榜,交回同一个 as_of 会让客户端
// 以为还能续页。后者:那一分钟还没闭合,窗口仍在增长。
func TestListByPopularity_StaleAsOfIsReplaced(t *testing.T) {
f := newFeedFixture(t)
ctx := context.Background()
f.seedHot(t, 1)
cases := []struct {
name string
asOf int64
}{
{name: "超出快照 TTL", asOf: f.asOf.Add(-3 * time.Hour).Unix()},
{name: "未来分钟", asOf: time.Now().UTC().Add(10 * time.Minute).Unix()},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
resp, err := f.svc.ListByPopularity(ctx, 10, c.asOf, 0, 0)
if err != nil {
t.Fatalf("ListByPopularity: %v", err)
}
if want := f.asOf.Unix(); resp.AsOf != want {
t.Fatalf("as_of = %d, want %d(不可采纳的 as_of 必须换成上一个闭合分钟)", resp.AsOf, want)
}
})
}
}