| 1 | package runner |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "io" |
| 6 | "log/slog" |
| 7 | "path/filepath" |
| 8 | "testing" |
| 9 | |
| 10 | "gitlab.com/Timfa/bluegit/internal/store" |
| 11 | ) |
| 12 | |
| 13 | func TestHoldKeepsJobsQueued(t *testing.T) { |
| 14 | dir := t.TempDir() |
| 15 | s, err := store.Open(filepath.Join(dir, "b.db"), make([]byte, 32)) |
| 16 | if err != nil { |
| 17 | t.Fatal(err) |
| 18 | } |
| 19 | defer s.Close() |
| 20 | ctx := context.Background() |
| 21 | tim, _ := s.UpsertUser(ctx, 1, "tim", "", false) |
| 22 | repo, err := s.CreateRepo(ctx, "user", tim.ID, "app", "", "master", "public") |
| 23 | if err != nil { |
| 24 | t.Fatal(err) |
| 25 | } |
| 26 | id, err := s.CreatePipeline(ctx, repo.ID, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "refs/heads/master", "push", "tim", "x", []store.NewJob{{Name: "build", Stage: "build", Script: "true"}}) |
| 27 | if err != nil { |
| 28 | t.Fatal(err) |
| 29 | } |
| 30 | held := 0 |
| 31 | r := &Runner{Store: s, Storage: dir, Docker: "/nonexistent/docker", GitBin: "git", Log: slog.New(slog.NewTextHandler(io.Discard, nil)), |
| 32 | Hold: func(p store.Pipeline) bool { held++; return p.ID == id }} |
| 33 | r.slots = make(chan struct{}, 1) |
| 34 | r.Tick(ctx) |
| 35 | jobs, _ := s.JobsByPipeline(ctx, id) |
| 36 | if held == 0 || jobs[0].Status != "queued" { |
| 37 | t.Fatalf("job niet vastgehouden: held=%d status=%s", held, jobs[0].Status) |
| 38 | } |
| 39 | } |