Download this file
| 1 | package team |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | "time" |
| 6 | ) |
| 7 | |
| 8 | func TestSmallClockRollbackPreservesLeaseAndCharge(t *testing.T) { |
| 9 | e := newEnv(t) |
| 10 | must(t, e.store.ConfigureBudgets(e.ctx, acctA, 0, periodSet())) |
| 11 | s, h := periodJob(e, 1) |
| 12 | e.clock.Advance(10 * time.Second) |
| 13 | before, err := e.store.Renew(e.ctx, s, h) |
| 14 | must(t, err) |
| 15 | e.clock.Advance(-time.Millisecond) |
| 16 | after, err := e.store.Renew(e.ctx, s, h) |
| 17 | must(t, err) |
| 18 | if !after.Equal(before) { |
| 19 | t.Fatal("clock correction moved lease", before, after) |
| 20 | } |
| 21 | must(t, e.store.StopAttempt(e.ctx, s, h, "test")) |
| 22 | must(t, e.store.Contain(e.ctx, s, h.Attempt, "supervisor")) |
| 23 | if u := periodUsage(e, 1); u.Spent.Seconds < 10 || u.Spent.Seconds > 11 { |
| 24 | t.Fatal("small rollback changed charge", u) |
| 25 | } |
| 26 | } |
| 27 | |