From 11d44d437081f6039d1e358d7d99838aecdca8e3 Mon Sep 17 00:00:00 2001 From: shivam Date: Sun, 3 Mar 2024 03:25:54 +0530 Subject: [PATCH 1/2] Creating Tests for the function submitJobs Signed-off-by: shivam --- internal/executor/job/submit.go | 4 ++-- internal/executor/job/submit_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/internal/executor/job/submit.go b/internal/executor/job/submit.go index 9943a0f3b68..8e033c4f8d3 100644 --- a/internal/executor/job/submit.go +++ b/internal/executor/job/submit.go @@ -53,7 +53,7 @@ type FailedSubmissionDetails struct { func (submitService *SubmitService) SubmitJobs(jobsToSubmit []*SubmitJob) []*FailedSubmissionDetails { return submitService.submitJobs(jobsToSubmit) -} +} func (submitService *SubmitService) submitJobs(jobsToSubmit []*SubmitJob) []*FailedSubmissionDetails { wg := &sync.WaitGroup{} @@ -110,7 +110,7 @@ func (submitService *SubmitService) submitWorker(wg *sync.WaitGroup, jobsToSubmi // submitPod submits a pod to k8s together with any services and ingresses bundled with the Armada job. // This function may fail partly, i.e., it may successfully create a subset of the requested objects before failing. // In case of failure, any already created objects are not cleaned up. -func (submitService *SubmitService) submitPod(job *SubmitJob) (*v1.Pod, error) { +func (submitService *SubmitService) submitPod(job *SubmitJob) (*v1.Pod, error) { //iska krna h pod := job.Pod // Ensure the K8SService and K8SIngress fields are populated submitService.applyExecutorSpecificIngressDetails(job) diff --git a/internal/executor/job/submit_test.go b/internal/executor/job/submit_test.go index e44e51980aa..33fce28a480 100644 --- a/internal/executor/job/submit_test.go +++ b/internal/executor/job/submit_test.go @@ -94,3 +94,30 @@ 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") +} \ No newline at end of file From cb1ca31d5c37ca2005b1767794a1fe47f312da9d Mon Sep 17 00:00:00 2001 From: shivam Date: Fri, 8 Mar 2024 05:57:44 +0530 Subject: [PATCH 2/2] Formatting files Signed-off-by: shivam --- internal/executor/job/submit.go | 5 ++--- internal/executor/job/submit_test.go | 12 +++++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/internal/executor/job/submit.go b/internal/executor/job/submit.go index 8e033c4f8d3..8dd86d78cc7 100644 --- a/internal/executor/job/submit.go +++ b/internal/executor/job/submit.go @@ -53,8 +53,7 @@ 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) @@ -110,7 +109,7 @@ func (submitService *SubmitService) submitWorker(wg *sync.WaitGroup, jobsToSubmi // submitPod submits a pod to k8s together with any services and ingresses bundled with the Armada job. // This function may fail partly, i.e., it may successfully create a subset of the requested objects before failing. // In case of failure, any already created objects are not cleaned up. -func (submitService *SubmitService) submitPod(job *SubmitJob) (*v1.Pod, error) { //iska krna h +func (submitService *SubmitService) submitPod(job *SubmitJob) (*v1.Pod, error) { pod := job.Pod // Ensure the K8SService and K8SIngress fields are populated submitService.applyExecutorSpecificIngressDetails(job) diff --git a/internal/executor/job/submit_test.go b/internal/executor/job/submit_test.go index 33fce28a480..e19a84d2df9 100644 --- a/internal/executor/job/submit_test.go +++ b/internal/executor/job/submit_test.go @@ -95,14 +95,13 @@ func newArmadaErrCreateResource() error { return &armadaerrors.ErrCreateResource{} } -func TestSubmitJobs(t *testing.T){ - submitService := &SubmitService{ - } +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)) @@ -111,8 +110,7 @@ func TestSubmitJobs(t *testing.T){ submitService.submitWorker = func(wg *sync.WaitGroup, submitJobs chan *SubmitJob, failedJobs chan *FailedSubmissionDetails) { for job := range submitJobs { - failedJobs <- &FailedSubmissionDetails{ - } + failedJobs <- &FailedSubmissionDetails{} } wg.Done() } @@ -120,4 +118,4 @@ func TestSubmitJobs(t *testing.T){ assert.NotNil(t, failedJobs, "Function did not returned slice of FailedSubmissionDetails") assert.Len(t, failedJobs, len(jobsToSubmit), "Unexpected length of failedJobs") -} \ No newline at end of file +}