diff --git a/backend/internal/feed/service_integration_test.go b/backend/internal/feed/service_integration_test.go index 70f4353..cc25dc1 100644 --- a/backend/internal/feed/service_integration_test.go +++ b/backend/internal/feed/service_integration_test.go @@ -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) + } + }) + } +}