| 1 | package runner |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "os" |
| 6 | "path/filepath" |
| 7 | "testing" |
| 8 | |
| 9 | "amadan.net/oficina/equipo/internal/equipo/team" |
| 10 | "amadan.net/oficina/equipo/internal/runner/provider" |
| 11 | "amadan.net/oficina/equipo/internal/runnerproto" |
| 12 | ) |
| 13 | |
| 14 | type supervisorAPI struct { |
| 15 | order *[]string |
| 16 | fail bool |
| 17 | } |
| 18 | |
| 19 | func (a *supervisorAPI) Call(_ context.Context, op string, q runnerproto.RunnerRequest, out any) error { |
| 20 | *a.order = append(*a.order, op) |
| 21 | if a.fail { |
| 22 | return provider.ErrUncertain |
| 23 | } |
| 24 | return nil |
| 25 | } |
| 26 | func cleanupFixture(t *testing.T) (*Supervisor, *attemptState, any, *[]string) { |
| 27 | t.Helper() |
| 28 | dir := t.TempDir() |
| 29 | os.Chmod(dir, 0700) |
| 30 | j, err := OpenJournal(context.Background(), filepath.Join(dir, "journal.db")) |
| 31 | if err != nil { |
| 32 | t.Fatal(err) |
| 33 | } |
| 34 | t.Cleanup(func() { j.Close() }) |
| 35 | order := []string{} |
| 36 | api := &supervisorAPI{order: &order} |
| 37 | s := &Supervisor{journal: j, api: api, clock: hostClock{}, states: map[string]*attemptState{}} |
| 38 | r := &attemptState{Claim: RunClaim{Assignment: runnerproto.Assignment{ID: "assignment", Kind: "step", StepKey: "reproduce"}, ClaimResponse: runnerproto.ClaimResponse{Scope: team.Scope{Account: "team", Job: 1}, Handle: team.Handle{Attempt: 1, Fence: 1, Runner: "runner"}}}, Owner: ProcessOwner{Attempt: 1, Fence: 1, Marker: "marker", AgentID: "agent", Workspace: provider.Workspace{ServerID: "server", WorkspaceID: "workspace", Path: t.TempDir()}}, Agent: provider.Agent{ServerID: "server", AgentID: "agent"}, Phase: "completed"} |
| 39 | s.states[attemptKey(r.Claim.Scope, r.Claim.Handle)] = r |
| 40 | if err := s.save(context.Background(), r); err != nil { |
| 41 | t.Fatal(err) |
| 42 | } |
| 43 | return s, r, nil, &order |
| 44 | } |
| 45 | |