mirror of
https://github.com/chenyme/grok2api.git
synced 2026-12-06 00:01:05 +00:00
test: prove auto-clean enable/wake never deletes immediately
Start the scheduler after enable and after a hot-reload wake; aged reauth accounts must remain until a timer tick runs the cleaner.
This commit is contained in:
1 parent
b848ba72bd
commit
87abeed580
1 file changed
+41
@@ -202,6 +202,47 @@ func TestSecondMarkReauthKeepsOriginalAnchor(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunAccountAutoCleanDoesNotDeleteOnEnableOrWake(t *testing.T) {
|
||||
now := time.Date(2026, 7, 20, 19, 0, 0, 0, time.UTC)
|
||||
service, repo := newAutoCleanTestService(t, now)
|
||||
aged := mustUpsert(t, repo, accountdomain.Credential{
|
||||
Provider: accountdomain.ProviderBuild, Name: "wake-aged", SourceKey: "wake-aged",
|
||||
EncryptedAccessToken: "x", Enabled: true, AuthStatus: accountdomain.AuthStatusReauthRequired,
|
||||
ReauthMarkedAt: ptrTime(now.Add(-2 * time.Hour)),
|
||||
})
|
||||
|
||||
// 启用只写入配置并唤醒;本身不删除。
|
||||
service.UpdateAutoCleanConfig(AutoCleanConfig{
|
||||
Enabled: true, Interval: time.Minute, MinAge: time.Hour,
|
||||
})
|
||||
assertPresent(t, repo, aged.ID)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
defer close(done)
|
||||
service.RunAccountAutoClean(ctx)
|
||||
}()
|
||||
|
||||
// 启动时会 drain 启动前 wake 并 arm timer;热更 wake 只重排 timer。
|
||||
time.Sleep(150 * time.Millisecond)
|
||||
assertPresent(t, repo, aged.ID)
|
||||
|
||||
service.UpdateAutoCleanConfig(AutoCleanConfig{
|
||||
Enabled: true, Interval: time.Minute, MinAge: time.Hour, IncludeDisabled: true,
|
||||
})
|
||||
time.Sleep(150 * time.Millisecond)
|
||||
assertPresent(t, repo, aged.ID)
|
||||
|
||||
cancel()
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(2 * time.Second):
|
||||
t.Fatal("auto-clean scheduler did not stop")
|
||||
}
|
||||
assertPresent(t, repo, aged.ID)
|
||||
}
|
||||
|
||||
func newAutoCleanTestService(t *testing.T, now time.Time) (*Service, *relational.AccountRepository) {
|
||||
t.Helper()
|
||||
ctx := context.Background()
|
||||
|
||||
Reference in new issue
Block a user