补充续期调度器唤醒测试
This commit is contained in:
parent
11cbd8a2f2
commit
b0e32b7825
@ -115,3 +115,53 @@ func TestRenewalSchedulerStopsRetryWhenContextCanceled(t *testing.T) {
|
||||
t.Fatalf("取消后的紧急续期重试报告错误:%+v calls=%d", report, len(service.ids))
|
||||
}
|
||||
}
|
||||
|
||||
type wakeRenewalLister struct {
|
||||
calls chan struct{}
|
||||
}
|
||||
|
||||
func (l *wakeRenewalLister) List(context.Context) ([]domain.Domain, error) {
|
||||
select {
|
||||
case l.calls <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func TestRenewalSchedulerUpdatePolicyWakesRunningScheduler(t *testing.T) {
|
||||
lister := &wakeRenewalLister{calls: make(chan struct{}, 4)}
|
||||
scheduler := NewRenewalSchedulerWithPolicy(lister, &renewalService{}, RenewalPolicy{
|
||||
CheckInterval: time.Hour,
|
||||
NearExpiryThreshold: 10 * 24 * time.Hour,
|
||||
RenewalThreshold: 6 * 24 * time.Hour,
|
||||
UrgentThreshold: 3 * 24 * time.Hour,
|
||||
MaxRetries: 3,
|
||||
RetryInterval: time.Minute,
|
||||
})
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
scheduler.Start(ctx)
|
||||
select {
|
||||
case <-lister.calls:
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("\u7eed\u671f\u8c03\u5ea6\u5668\u542f\u52a8\u540e\u672a\u6267\u884c\u9996\u6b21\u68c0\u67e5")
|
||||
}
|
||||
|
||||
scheduler.UpdatePolicy(RenewalPolicy{
|
||||
CheckInterval: 2 * time.Hour,
|
||||
NearExpiryThreshold: 12 * 24 * time.Hour,
|
||||
RenewalThreshold: 8 * 24 * time.Hour,
|
||||
UrgentThreshold: 4 * 24 * time.Hour,
|
||||
MaxRetries: 5,
|
||||
RetryInterval: 2 * time.Minute,
|
||||
})
|
||||
if got := scheduler.Policy(); got.CheckInterval != 2*time.Hour || got.NearExpiryThreshold != 12*24*time.Hour || got.RenewalThreshold != 8*24*time.Hour || got.UrgentThreshold != 4*24*time.Hour || got.MaxRetries != 5 || got.RetryInterval != 2*time.Minute {
|
||||
t.Fatalf("\u8fd0\u884c\u65f6\u7eed\u671f\u7b56\u7565\u672a\u66f4\u65b0\uff1a%+v", got)
|
||||
}
|
||||
select {
|
||||
case <-lister.calls:
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("\u66f4\u65b0\u7eed\u671f\u7b56\u7565\u540e\u8c03\u5ea6\u5668\u672a\u88ab\u7acb\u5373\u5524\u9192")
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user