Skip to content
Snippets Groups Projects
Select Git revision
  • ea2b52f293662a7920d5b72cfbe5dd69b44ab040
  • master default protected
  • 1.31
  • 4.28.0
  • 4.27.0
  • 4.26.0
  • 4.25.5
  • 4.25.4
  • 4.25.3
  • 4.25.2
  • 4.25.1
  • 4.25.0
  • 4.24.3
  • 4.24.2
  • 4.24.1
  • 4.24.0
  • 4.23.6
  • 4.23.5
  • 4.23.4
  • 4.23.3
  • 4.23.2
  • 4.23.1
  • 4.23.0
23 results

test.html

Blame
  • issue-1_test.go 1.71 KiB
    //go:build !runOnTask
    
    package jobqueue
    
    import (
    	"github.com/robfig/cron/v3"
    	"github.com/stretchr/testify/assert"
    	"go.uber.org/zap"
    
    	"strings"
    	"testing"
    	"time"
    )
    
    // TestRoundTrip tests the round trip of jobs from yaml to the manager and back to yaml
    // This test runs forever and must be stopped manually
    // Use the following command to run this test:
    // go test -timeout 6h -run TestRoundTrip -v
    func TestRoundTrip(t *testing.T) {
    
    	// define test data with jobs in yaml format
    	testData := []byte(`
    - id: job1
      priority: 1
      timeout: 1s
      maxRetries: 3
      retryDelay: 1s
      runnable:
       type: shell
       data:
         script: echo "~1~ $(date "+%M:%S")" >> /tmp/job1.log
      scheduler:
       type: cron
       spec: "*/10 * * * * *"
    - id: job2
      priority: 1
      timeout: 1s
      maxRetries: 3
      retryDelay: 1s
      runnable:
       type: shell
       data:
         script: echo "~~~~2~ $(date "+%M:%S")" >> /tmp/job1.log
      scheduler:
       type: cron
       spec: "*/5 * * * * *"
    - id: job3
      priority: 1
      timeout: 1s
      maxRetries: 3
      retryDelay: 1s
      runnable:
        type: shell
        data:
          script: echo "~~~~~~3~ $(date "+%M:%S")" >> /tmp/job1.log
      scheduler:
        type: interval
        interval: 20s
    `)
    
    	var err error
    
    	cronInstance := cron.New(cron.WithSeconds())
    	cronInstance.Start()
    
    	zapLogger, _ := zap.NewDevelopment()
    	_ = zapLogger
    
    	manager := NewManager()
    	manager.SetLogger(&ZapAdapter{logger: zapLogger})
    
    	manager.SetCronInstance(cronInstance)
    	worker := NewLocalWorker(10)
    	worker.SetManager(manager)
    	err = manager.AddWorker(worker)
    
    	assert.Nil(t, err)
    
    	err = manager.Start()
    	assert.Nil(t, err)
    
    	reader := strings.NewReader(string(testData))
    
    	err = ImportJobsAndSchedule(reader, "yaml", manager)
    	assert.Nil(t, err)
    
    	for {
    		time.Sleep(1 * time.Second)
    	}
    
    }