From 0fcbf3ae00d3199262d68c3d3b5b51e113249c17 Mon Sep 17 00:00:00 2001 From: huanghaosheng <386998068@qq.com> Date: Sun, 1 Nov 2026 15:16:56 +0800 Subject: [PATCH] =?UTF-8?q?test(feed):=20=E8=A6=86=E7=9B=96=E8=BF=87?= =?UTF-8?q?=E6=9C=9F=E4=B8=8E=E6=9C=AA=E6=9D=A5=20as=5Fof=20=E7=9A=84?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 过期的 as_of 超出快照 TTL。服务端换回上一个闭合分钟,客户端据此重置分页。 未来的 as_of 属于仍未闭合的分钟。窗口还在增长,同样不能采纳。 验证:MYSQL_TEST_DSN=... go test -tags integration -count=1 -p 1 -run TestListByPopularity ./internal/feed/ 通过。 --- .../internal/feed/service_integration_test.go | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) 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) + } + }) + } +}