Skip to content
Snippets Groups Projects
Select Git revision
  • 62b2e326c52bfa8a4e290b343a395fde212b5a66
  • master default protected
  • v1.23.2
  • v1.23.1
  • v1.23.0
  • v1.22.0
  • v1.21.1
  • v1.21.0
  • v1.20.3
  • v1.20.2
  • v1.20.1
  • v1.20.0
  • v1.19.4
  • v1.19.3
  • v1.19.2
  • v1.19.1
  • v1.19.0
  • v1.18.2
  • v1.18.1
  • v1.18.0
  • v1.17.0
  • v1.16.1
22 results

job_test.go

Blame
  • job_test.go 3.91 KiB
    package jobqueue
    
    import (
    	"context"
    	"github.com/stretchr/testify/assert"
    	"os"
    	"path"
    	"testing"
    	"time"
    )
    
    func TestNewJob(t *testing.T) {
    	runner := &ShellRunnable{ScriptPath: "path"}
    	job := NewJob[ShellResult]("id1", runner)
    	assert.Equal(t, JobID("id1"), job.GetID())
    	assert.Equal(t, PriorityDefault, job.GetPriority())
    }
    
    func TestSetPriority(t *testing.T) {
    	job := NewJob[ShellResult]("id1", &ShellRunnable{})
    	job.SetPriority(PriorityHigh)
    	assert.Equal(t, PriorityHigh, job.GetPriority())
    }
    
    func TestSetAndGetTimeout(t *testing.T) {
    	job := NewJob[ShellResult]("id1", &ShellRunnable{})
    	job.SetTimeout(5 * time.Minute)
    	assert.Equal(t, 5*time.Minute, job.GetTimeout())
    }
    
    func TestSetAndGetMaxRetries(t *testing.T) {
    	job := NewJob[ShellResult]("id1", &ShellRunnable{})
    	job.SetMaxRetries(5)
    	assert.Equal(t, uint(5), job.GetMaxRetries())
    }
    
    func TestSetAndGetRunnable(t *testing.T) {
    	runner := &ShellRunnable{ScriptPath: "path"}
    	job := NewJob[ShellResult]("id1", runner)
    	assert.Equal(t, runner, job.GetRunnable())
    }
    
    func TestSetAndGetRetryDelay(t *testing.T) {
    	job := NewJob[ShellResult]("id1", &ShellRunnable{})
    	job.SetRetryDelay(2 * time.Second)
    	assert.Equal(t, 2*time.Second, job.GetRetryDelay())
    }
    
    func TestSetAndGetDependencies(t *testing.T) {
    	job := NewJob[ShellResult]("id1", &ShellRunnable{})
    	job.SetDependencies([]JobID{"id2", "id3"})
    	assert.Equal(t, []JobID{"id2", "id3"}, job.GetDependencies())
    }
    
    type TestScheduler struct{}
    
    func (s *TestScheduler) Schedule(job *GenericJob, eventBus *EventBus, stopChan chan bool) error {
    	return nil
    }
    
    func TestGetID(t *testing.T) {
    	job := NewJob[ShellResult]("id1", &ShellRunnable{})
    	assert.Equal(t, JobID("id1"), job.GetID())
    }
    
    func TestGetRunnable(t *testing.T) {
    	runner := &ShellRunnable{ScriptPath: "path"}
    	job := NewJob[ShellResult]("id1", runner)
    	assert.Equal(t, runner, job.GetRunnable())
    }