feat: establish Orbit models, migrations and development baseline
This commit is contained in:
38
weave/model/poll_policy_test.go
Normal file
38
weave/model/poll_policy_test.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"errors"
|
||||
core "git.yuntuo.hk/k2safe/orbit/model"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestPollRecoveryPreservesBudgetAndDeadline(t *testing.T) {
|
||||
now := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
p := PollState{MaxRounds: 3, UsedRounds: 2, DeadlineAt: now.Add(time.Minute), NextPollAt: &now}
|
||||
n, err := p.NextRound(now)
|
||||
if err != nil || n != 3 {
|
||||
t.Fatalf("next round: %d %v", n, err)
|
||||
}
|
||||
p.UsedRounds = 3
|
||||
if _, err := p.NextRound(now); !errors.Is(err, ErrPollExhausted) {
|
||||
t.Fatal("counter reset or limit bypass")
|
||||
}
|
||||
p.UsedRounds = 2
|
||||
if _, err := p.NextRound(p.DeadlineAt); !errors.Is(err, ErrPollExhausted) {
|
||||
t.Fatal("deadline equality permitted new round")
|
||||
}
|
||||
task := core.ID("00000000000000000000000000000001")
|
||||
p.CurrentTaskID = &task
|
||||
if _, err := p.NextRound(now); !errors.Is(err, ErrPollInFlight) {
|
||||
t.Fatal("overlapping poll round permitted")
|
||||
}
|
||||
}
|
||||
func TestResumeDoesNotClearReviewOrCancellation(t *testing.T) {
|
||||
now := time.Now()
|
||||
for _, i := range []Instance{{State: InstanceRunning, Paused: true}, {State: InstanceNeedsReview}, {State: InstanceCancelling}, {State: InstanceRunning, CancelRequestedAt: &now}, {State: InstanceSucceeded}, {State: InstanceState("future")}} {
|
||||
if i.AllowsNewWork() {
|
||||
t.Fatalf("allowed new work: %+v", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user