sim: move the I8 grant checks out of check, under the length limit
make code-health found check at 308 code lines, over the 300 a new function may have. The checks are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+27
−21
internal/sim/mediajobs/invariants_test.go+27 −21
diff --git a/internal/sim/mediajobs/invariants_test.go b/internal/sim/mediajobs/invariants_test.go| index 5ba56e2e8..e7b265182 100644 |
| --- a/internal/sim/mediajobs/invariants_test.go |
| +++ b/internal/sim/mediajobs/invariants_test.go |
| @@ -552,27 +552,7 @@ func check(w *world) { |
| } |
| } |
| } |
| - // I8 (grant). |
| - for _, r := range rows { |
| - if r.Execution == "" { |
| - continue |
| - } |
| - k := media.ClassKey{Preset: r.Preset, Class: r.Class} |
| - spec, ok := media.Class(k) |
| - if !ok { |
| - w.fail("I8", "row %s was dispatched in class %s, which has no row", shortID(r.JobID), k) |
| - continue |
| - } |
| - if most := w.limits.Granted(k).Milliseconds(); r.GrantedS*1000 > most { |
| - w.fail("I8", "row %s %s was granted %d s, over its class's %d ms", shortID(r.JobID), k, r.GrantedS, most) |
| - } |
| - if most := min(spec.Deadline, media.MaxDeadline).Milliseconds(); r.DeadlineS*1000 > most { |
| - w.fail("I8", "row %s %s has a deadline of %d s, over its class's %d ms", shortID(r.JobID), k, r.DeadlineS, most) |
| - } |
| - if r.State == "done" && r.SourceMS > r.GrantedS*1000 { |
| - w.fail("I8", "row %s is done with a %d ms source, longer than its %d s grant", shortID(r.JobID), r.SourceMS, r.GrantedS) |
| - } |
| - } |
| + checkGrants(w, rows) |
| for _, a := range accounts { |
| if limit := w.allowance[a]; limit > 0 { |
| if most := 2 * limit * 600000; used[a] > most { |
| @@ -745,6 +725,32 @@ func (w *world) checkPrune(prune func() error) error { |
| return nil |
| } |
| +// checkGrants is I8 (grant) over the rows: each dispatched row's grant and |
| +// deadline within its class's figures, and a done row's source no longer |
| +// than its grant. |
| +func checkGrants(w *world, rows []row) { |
| + for _, r := range rows { |
| + if r.Execution == "" { |
| + continue |
| + } |
| + k := media.ClassKey{Preset: r.Preset, Class: r.Class} |
| + spec, ok := media.Class(k) |
| + if !ok { |
| + w.fail("I8", "row %s was dispatched in class %s, which has no row", shortID(r.JobID), k) |
| + continue |
| + } |
| + if most := w.limits.Granted(k).Milliseconds(); r.GrantedS*1000 > most { |
| + w.fail("I8", "row %s %s was granted %d s, over its class's %d ms", shortID(r.JobID), k, r.GrantedS, most) |
| + } |
| + if most := min(spec.Deadline, media.MaxDeadline).Milliseconds(); r.DeadlineS*1000 > most { |
| + w.fail("I8", "row %s %s has a deadline of %d s, over its class's %d ms", shortID(r.JobID), k, r.DeadlineS, most) |
| + } |
| + if r.State == "done" && r.SourceMS > r.GrantedS*1000 { |
| + w.fail("I8", "row %s is done with a %d ms source, longer than its %d s grant", shortID(r.JobID), r.SourceMS, r.GrantedS) |
| + } |
| + } |
| +} |
| + |
| // checkPayload is I8 (grant) for one Run: the payload's limits are the |
| // row's grant and the deployment's duration maximums for its preset. |
| func (w *world) checkPayload(r row) { |