MCPcopy Create free account
hub / github.com/compozy/agh / TestManagerRecoverRunOnBoot

Function TestManagerRecoverRunOnBoot

internal/task/manager_test.go:8423–8781  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8421}
8422
8423func TestManagerRecoverRunOnBoot(t *testing.T) {
8424 t.Parallel()
8425
8426 daemonActor, err := DeriveDaemonActorContext("boot-recovery", "daemon.boot")
8427 if err != nil {
8428 t.Fatalf("DeriveDaemonActorContext() error = %v", err)
8429 }
8430
8431 t.Run("Should claimed run requeues and records recovery event", func(t *testing.T) {
8432 t.Parallel()
8433
8434 store := newInMemoryManagerStore()
8435 manager := newTaskManagerForTest(t, store)
8436 actor := validActorContext()
8437
8438 taskRecord, err := manager.CreateTask(context.Background(), CreateTask{
8439 Scope: ScopeGlobal,
8440 Title: "Claimed recovery",
8441 }, actor)
8442 if err != nil {
8443 t.Fatalf("CreateTask() error = %v", err)
8444 }
8445 run, err := manager.EnqueueRun(
8446 context.Background(),
8447 EnqueueRun{TaskID: taskRecord.ID},
8448 actor,
8449 )
8450 if err != nil {
8451 t.Fatalf("EnqueueRun() error = %v", err)
8452 }
8453 run, err = manager.ClaimRun(context.Background(), run.ID, ClaimRun{}, actor)
8454 if err != nil {
8455 t.Fatalf("ClaimRun() error = %v", err)
8456 }
8457
8458 recovered, err := manager.RecoverRunOnBoot(context.Background(), run.ID, RunBootRecovery{
8459 Action: RunBootRecoveryRequeue,
8460 Reason: "orphaned_on_boot",
8461 SessionState: "missing",
8462 }, daemonActor)
8463 if err != nil {
8464 t.Fatalf("RecoverRunOnBoot(requeue) error = %v", err)
8465 }
8466 if got, want := recovered.Status, TaskRunStatusQueued; got != want {
8467 t.Fatalf("recovered.Status = %q, want %q", got, want)
8468 }
8469 if recovered.ClaimedBy != nil {
8470 t.Fatalf("recovered.ClaimedBy = %#v, want nil", recovered.ClaimedBy)
8471 }
8472 if !store.runs[run.ID].ClaimedAt.IsZero() {
8473 t.Fatalf(
8474 "store.runs[%q].ClaimedAt = %v, want zero",
8475 run.ID,
8476 store.runs[run.ID].ClaimedAt,
8477 )
8478 }
8479
8480 events, err := store.ListTaskEvents(context.Background(), EventQuery{TaskID: taskRecord.ID})

Callers

nothing calls this directly

Calls 15

DeriveDaemonActorContextFunction · 0.85
newInMemoryManagerStoreFunction · 0.85
newTaskManagerForTestFunction · 0.85
validActorContextFunction · 0.85
WithSessionExecutorFunction · 0.85
RecoverRunOnBootMethod · 0.80
ContainsMethod · 0.80
containsEventTypeFunction · 0.70
sortedEventTypesFunction · 0.70
RunMethod · 0.65
CreateTaskMethod · 0.65

Tested by

no test coverage detected