~james/core

core/spindle/mill/workflow_limit_test.go -rw-r--r-- 1.5 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 16 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package mill

import (
	"context"
	"errors"
	"strings"
	"testing"

	"tangled.org/core/spindle/models"
	"tangled.org/core/spindle/quota"
)

var bigWorkflowRefusal = quota.Reservation{
	Reason:    quota.ReasonRepoLimit,
	Resource:  quota.ResourceWorkflowVCPUs,
	Scope:     quota.ScopeRepo,
	Requested: 6,
	Limit:     2,
}

func placeBigWorkflow(t *testing.T, verdicts ...quota.Reservation) (*quotaCandidate, error) {
	t.Helper()
	m, _ := quotaMill(t, &scriptedStore{verdicts: verdicts})
	cand := addQuotaCandidate(t, m, "node-a", fixedReport(6, 2048))
	wid := models.WorkflowId{PipelineId: models.PipelineId("rkey1"), Name: "build"}
	slot, err := m.place(context.Background(), "dummy", wid, testWorkflow("build"))
	if err == nil {
		slot.Release()
	}
	if !errors.Is(err, quota.ErrDenied) {
		t.Fatalf("place error = %v, want a refusal", err)
	}
	// a prefix added to the refusal would show up in front of it in the workflow status
	if msg := err.Error(); strings.Contains(msg, ": ") || !strings.Contains(msg, "6 vCPUs") || !strings.Contains(msg, "2 vCPUs") {
		t.Fatalf("place error = %q, want just the refusal with both amounts", msg)
	}
	return cand, err
}

func TestPlaceRefusesWorkflowOverItsLimit(t *testing.T) {
	cand, _ := placeBigWorkflow(t, bigWorkflowRefusal)
	if _, released := cand.counts(); released != 1 {
		t.Errorf("executor seat releases = %d, want 1", released)
	}
}

func TestPlaceRefusesWorkflowOverItsLimitBehindAQueue(t *testing.T) {
	placeBigWorkflow(t, quota.Reservation{Temporary: true, Reason: quota.ReasonRepoLimit}, bigWorkflowRefusal)
}