feat: enforce shared application resource quotas across namespaces
This commit is contained in:
@@ -106,7 +106,11 @@ func TestIntegrationSchedules(t *testing.T) {
|
||||
f := fixture(t)
|
||||
finite := func(delay time.Duration) schedule.Definition {
|
||||
in := f.definition()
|
||||
in.Rule.StartAt = time.Now().UTC().Truncate(time.Microsecond).Add(delay)
|
||||
var now time.Time
|
||||
if err := db.QueryRowContext(ctx, `SELECT UTC_TIMESTAMP(6)`).Scan(&now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
in.Rule.StartAt = now.Add(delay)
|
||||
end := in.Rule.StartAt.Add(time.Millisecond)
|
||||
in.Rule.EndAt = &end
|
||||
return in
|
||||
@@ -122,12 +126,20 @@ func TestIntegrationSchedules(t *testing.T) {
|
||||
}
|
||||
waitUntil := func(at time.Time) {
|
||||
t.Helper()
|
||||
timer := time.NewTimer(time.Until(at.Add(10 * time.Millisecond)))
|
||||
defer timer.Stop()
|
||||
select {
|
||||
case <-timer.C:
|
||||
case <-ctx.Done():
|
||||
t.Fatal(ctx.Err())
|
||||
// 调度使用数据库时间,不能依赖容器与宿主机时钟完全同步。
|
||||
for {
|
||||
var now time.Time
|
||||
if err := db.QueryRowContext(ctx, `SELECT UTC_TIMESTAMP(6)`).Scan(&now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if now.After(at) {
|
||||
return
|
||||
}
|
||||
select {
|
||||
case <-time.After(10 * time.Millisecond):
|
||||
case <-ctx.Done():
|
||||
t.Fatal(ctx.Err())
|
||||
}
|
||||
}
|
||||
}
|
||||
v := f.create(finite(300 * time.Millisecond))
|
||||
@@ -146,7 +158,7 @@ func TestIntegrationSchedules(t *testing.T) {
|
||||
f.tick() // 第一版本结束,第二版本尚未计算第一个触发点。
|
||||
pending := f.current(v.ID)
|
||||
if pending.ProcessingVersion != 2 || pending.NextFireAt != nil || pending.CheckAt == nil {
|
||||
t.Fatal("expected pending initialization of version 2")
|
||||
t.Fatalf("expected pending initialization of version 2: processing=%d next=%v check=%v current=%d occurrences=%d", pending.ProcessingVersion, pending.NextFireAt, pending.CheckAt, pending.CurrentVersion, len(f.occurrences(v.ID)))
|
||||
}
|
||||
if !emptyMiddle {
|
||||
waitUntil(middle.Rule.StartAt)
|
||||
|
||||
Reference in New Issue
Block a user