Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating Tests for the function submitJobs #3438

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion internal/executor/job/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ type FailedSubmissionDetails struct {
func (submitService *SubmitService) SubmitJobs(jobsToSubmit []*SubmitJob) []*FailedSubmissionDetails {
return submitService.submitJobs(jobsToSubmit)
}

func (submitService *SubmitService) submitJobs(jobsToSubmit []*SubmitJob) []*FailedSubmissionDetails {
wg := &sync.WaitGroup{}
submitJobsChannel := make(chan *SubmitJob)
Expand Down
25 changes: 25 additions & 0 deletions internal/executor/job/submit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,28 @@ func newArbitraryError(message string) error {
func newArmadaErrCreateResource() error {
return &armadaerrors.ErrCreateResource{}
}

func TestSubmitJobs(t *testing.T) {
submitService := &SubmitService{}
job1 := &SubmitJob{}
job2 := &SubmitJob{}

jobsToSubmit := []*SubmitJob{job1, job2}

submitJobsChannel := make(chan *SubmitJob)
failedJobsChannel := make(chan *FailedSubmissionDetails, len(jobsToSubmit))

assert.NotNil(t, submitJobsChannel, "Failed to create submitJobsChannel")
assert.NotNil(t, failedJobsChannel, "Failed to create failedJobsChannel")

submitService.submitWorker = func(wg *sync.WaitGroup, submitJobs chan *SubmitJob, failedJobs chan *FailedSubmissionDetails) {
for job := range submitJobs {
failedJobs <- &FailedSubmissionDetails{}
}
wg.Done()
}
failedJobs := submitService.submitJobs(jobsToSubmit)

assert.NotNil(t, failedJobs, "Function did not returned slice of FailedSubmissionDetails")
assert.Len(t, failedJobs, len(jobsToSubmit), "Unexpected length of failedJobs")
}