diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-04-27 21:20:10 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-04-27 21:20:10 +0900 |
| commit | cb00405041ee4714b6e817e9570cfa10ae972840 (patch) | |
| tree | ff98728b3e5e099eb9ac5556eeb407c68e0fc208 /backend/cmd/serve_test.go | |
| parent | 938863425bf8ad6c17e43b3da128f92cf6d6ab63 (diff) | |
| download | feedaka-cb00405041ee4714b6e817e9570cfa10ae972840.tar.gz feedaka-cb00405041ee4714b6e817e9570cfa10ae972840.tar.zst feedaka-cb00405041ee4714b6e817e9570cfa10ae972840.zip | |
Add per-feed fetch_interval_seconds (clamped to [1h, 24h]) that halves
on new articles and grows 1.5x when a fetch yields nothing, replacing
the fixed 1h schedule with the 10min cooldown filter. Scheduler tick
shortened to 30min so the 1h floor is honored with reasonable precision.
Diffstat (limited to 'backend/cmd/serve_test.go')
| -rw-r--r-- | backend/cmd/serve_test.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/backend/cmd/serve_test.go b/backend/cmd/serve_test.go new file mode 100644 index 0000000..82b7d53 --- /dev/null +++ b/backend/cmd/serve_test.go @@ -0,0 +1,30 @@ +package cmd + +import "testing" + +func TestNextFetchInterval(t *testing.T) { + tests := []struct { + name string + current int64 + hadNewArticles bool + want int64 + }{ + {"new articles halve from mid-range", 14400, true, 7200}, + {"new articles halve from max", maxFetchIntervalSeconds, true, 43200}, + {"new articles clamp at min when halving below", 3600, true, minFetchIntervalSeconds}, + {"new articles clamp at min from slightly above", 4000, true, minFetchIntervalSeconds}, + {"no articles grow by 1.5x from min", minFetchIntervalSeconds, false, 5400}, + {"no articles grow by 1.5x from mid-range", 14400, false, 21600}, + {"no articles clamp at max", maxFetchIntervalSeconds, false, maxFetchIntervalSeconds}, + {"no articles clamp at max from slightly below", 60000, false, maxFetchIntervalSeconds}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := nextFetchInterval(tt.current, tt.hadNewArticles) + if got != tt.want { + t.Errorf("nextFetchInterval(%d, %v) = %d, want %d", tt.current, tt.hadNewArticles, got, tt.want) + } + }) + } +} |
