test(job-array-one-based-index): apiserver handler test seams and fixture (task 5.4)
CreateJob's ID generation and submission and both control dispatch sites now go through package variables (generateJobID, generateArrayJobID, submitJob, controlJob) that default to the real backend/services functions, so production behaviour is unchanged. A new non-cgo handler test file provides a reusable fixture: it saves and restores every global it touches, sets up auth/RBAC, seeds jobs and their queues, and records each dispatched job. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
46f57095c1
commit
3a7e3890e2
3 changed files with 490 additions and 5 deletions
|
|
@ -1423,7 +1423,7 @@ func (j JobController) CreateJob(ctx *gin.Context) {
|
|||
}
|
||||
|
||||
// Generate job ID via C idgen (single call for both normal and array jobs)
|
||||
jobID, err := backend.GenerateJobID(clusterID, apiserverID, arraySize)
|
||||
jobID, err := generateJobID(clusterID, apiserverID, arraySize)
|
||||
if err != nil {
|
||||
logger.Error("Failed to generate job ID", zap.Error(err))
|
||||
ReturnError(ctx, common.ERROR_CODE, "failed to generate job ID: "+err.Error(), nil)
|
||||
|
|
@ -1505,7 +1505,7 @@ func (j JobController) CreateJob(ctx *gin.Context) {
|
|||
logger.Debug("jobinfo before submit.", zap.Any("job", job))
|
||||
|
||||
// Submit job to backend (single call handles both normal and array)
|
||||
err = services.SubmitJob(&job, arraySize)
|
||||
err = submitJob(&job, arraySize)
|
||||
if err != nil {
|
||||
logger.Error("Failed to submit job.", zap.Error(err))
|
||||
ReturnError(ctx, common.ERROR_CODE, common.ERROR_WRITE_DATA_MSG+": "+err.Error(), nil)
|
||||
|
|
@ -1534,6 +1534,17 @@ func preCheckJobRestartRequest(req *models.JobRestartRequest) error {
|
|||
// preCheckJobRequest; a variable so tests can substitute it (bug-1744).
|
||||
var validateResreqSyntax = backend.ValidateResreqSyntax
|
||||
|
||||
// Backend seams used by CreateJob, ControlJobByID and the filter-based
|
||||
// ControlJob; variables (like validateResreqSyntax) so the non-cgo handler
|
||||
// tests (jobs_handler_test.go) can replace them and observe ID allocation,
|
||||
// submission and control dispatch. Production code never reassigns them.
|
||||
var (
|
||||
generateJobID = backend.GenerateJobID
|
||||
generateArrayJobID = backend.GenerateArrayJobID
|
||||
submitJob = services.SubmitJob
|
||||
controlJob = backend.ControlJob
|
||||
)
|
||||
|
||||
func preCheckJobRequest(req *models.JobSubmitRequest) ([]int, error) {
|
||||
logger.Debug("Enter preCheckJobRequest")
|
||||
if req.QueueName == "" {
|
||||
|
|
@ -2608,7 +2619,7 @@ func (j JobController) ControlJobByID(ctx *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
err = backend.ControlJob(uint64(successJob["unique_job_id"].(int64)), acttype, string(jobCtrlEvtBytes))
|
||||
err = controlJob(uint64(successJob["unique_job_id"].(int64)), acttype, string(jobCtrlEvtBytes))
|
||||
if err != nil {
|
||||
logger.Error("send job control to backend error", zap.Error(err))
|
||||
ReturnError(ctx, common.ERROR_CODE, common.ERROR_WRITE_DATA_MSG+": "+err.Error(), nil)
|
||||
|
|
@ -2844,7 +2855,7 @@ func (j JobController) ControlJob(ctx *gin.Context) {
|
|||
ReturnError(ctx, common.ERROR_CODE, "encode job control event error:"+": "+err.Error(), nil)
|
||||
return
|
||||
}
|
||||
err = backend.ControlJob(uint64(successJob["unique_job_id"].(int64)), acttype, string(jobCtrlEvtBytes))
|
||||
err = controlJob(uint64(successJob["unique_job_id"].(int64)), acttype, string(jobCtrlEvtBytes))
|
||||
if err != nil {
|
||||
logger.Error("send job control to backend error", zap.Error(err))
|
||||
ReturnError(ctx, common.ERROR_CODE, common.ERROR_WRITE_DATA_MSG+": "+err.Error(), nil)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue