fix(apiserver): check the default queue exists and is open on submit (bug-1960)

Cause: preCheckJobRequest (controllers/jobs.go) ran the reserved-name,
existence and closed checks only when a queue name was given; an empty
name was set to "normal" and skipped them, so jobs were accepted into a
closed default queue.

Fix: default the name first, then run the same checks for every
submission. Two existing tests now seed the default queue. (The controller
side of bug-1960 is fixed separately.)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Rongsong Shen 2026-10-10 10:25:45 +00:00
parent 387a421c57
commit 1ff068f6e7
Signed by untrusted user: rshen
GPG key ID: 80533536B0EB651C
3 changed files with 63 additions and 19 deletions

View file

@ -122,6 +122,47 @@ func TestPreCheckJobRequest_EmptyQueue(t *testing.T) {
}
}
// bug-1960: a submission without a queue goes to the default queue "normal",
// which must pass the same closed check as an explicitly named queue.
func TestPreCheckJobRequest_DefaultQueueClosed(t *testing.T) {
resetJobSubmitState()
store.Queues.Put("normal", models.QueueInfo{
QueueName: "normal",
QueueStatus: int(models.QUEUESTAT["CLOSED"]),
})
req := &models.JobSubmitRequest{QueueName: "", Command: "sleep 1"}
_, _, err := preCheckJobRequest(req)
if err == nil || !strings.Contains(err.Error(), "queue is closed") {
t.Fatalf("submission to the closed default queue: err = %v, want \"queue is closed\"", err)
}
}
// bug-1960: the default queue must also exist, as a named queue must.
func TestPreCheckJobRequest_DefaultQueueMissing(t *testing.T) {
resetJobSubmitState()
req := &models.JobSubmitRequest{QueueName: "", Command: "sleep 1"}
_, _, err := preCheckJobRequest(req)
if err == nil || !strings.Contains(err.Error(), "invalid queue name: normal") {
t.Fatalf("submission with no default queue: err = %v, want \"invalid queue name: normal\"", err)
}
}
// bug-1960: an open default queue is still accepted and filled in.
func TestPreCheckJobRequest_DefaultQueueOpen(t *testing.T) {
resetJobSubmitState()
store.Queues.Put("normal", models.QueueInfo{QueueName: "normal"})
req := &models.JobSubmitRequest{QueueName: "", Command: "sleep 1"}
if _, _, err := preCheckJobRequest(req); err != nil {
t.Fatalf("submission to the open default queue rejected: %v", err)
}
if req.QueueName != "normal" {
t.Errorf("QueueName = %q, want normal", req.QueueName)
}
}
// TestValidateJobControl_HandlesRealJobInfoTypes is a regression guard for
// bug-1742 (gitea #45): models.JobInfo.JobStatus and .ArrayIdx are plain Go
// `int` (see the JobInfo struct in models/jobs.go), but validateJobControl
@ -278,6 +319,7 @@ func TestPreCheckJobRequest_NamedJobsGetFullValidation(t *testing.T) {
origCfg := utils.JobYamlConfig
utils.JobYamlConfig = &utils.JobConfig{MaxArraySize: 1000}
t.Cleanup(func() { utils.JobYamlConfig = origCfg })
store.Queues.Put("normal", models.QueueInfo{QueueName: "normal"}) // default queue (bug-1960)
for _, name := range []string{"", "myjob", "arr[1-3]"} {
req := &models.JobSubmitRequest{JobName: name, Command: "sleep 1"}