Add durable run liveness assessment
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package work_recovery_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.cin.su/m/Assistant/contracts/work"
|
||||
workdomain "git.cin.su/m/Assistant/modules/work/domain"
|
||||
)
|
||||
|
||||
func TestAssessRunLivenessClassifiesDurableHeartbeat(t *testing.T) {
|
||||
now := time.UnixMilli(10000)
|
||||
run := work.AgentRun{ID: "run-1", DelegationID: "delegation-1", ImplementationID: "agent-1", ImplementationRevision: 1, Protocol: work.AgentExecutionProtocol("v1"), State: work.AgentRunRunning, StartedAtUnixMillis: 9000, UpdatedAtUnixMillis: 9000}
|
||||
if got := workdomain.AssessRunLiveness(run, now.Add(100*time.Millisecond), time.Second); got.State != workdomain.RunLivenessStale || got.Age != 1100*time.Millisecond {
|
||||
t.Fatalf("stale = %#v", got)
|
||||
}
|
||||
run.UpdatedAtUnixMillis = 9500
|
||||
if got := workdomain.AssessRunLiveness(run, now, time.Second); got.State != workdomain.RunLivenessLive {
|
||||
t.Fatalf("live = %#v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAssessRunLivenessDoesNotTreatCompletedAsStale(t *testing.T) {
|
||||
run := work.AgentRun{State: work.AgentRunCompleted, UpdatedAtUnixMillis: 1}
|
||||
got := workdomain.AssessRunLiveness(run, time.UnixMilli(10000), time.Second)
|
||||
if got.State != workdomain.RunLivenessNotRun {
|
||||
t.Fatalf("completed = %#v", got)
|
||||
}
|
||||
invalid := workdomain.AssessRunLiveness(run, time.Time{}, time.Second)
|
||||
if invalid.State != workdomain.RunLivenessInvalid {
|
||||
t.Fatalf("invalid = %#v", invalid)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user