34 lines
		
	
	
		
			657 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
		
			657 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package scheduler
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 	"cycle-scheduler/internal/job"
 | |
| 	"errors"
 | |
| 	"testing"
 | |
| 	"time"
 | |
| 
 | |
| 	"github.com/stretchr/testify/assert"
 | |
| )
 | |
| 
 | |
| func TestSlot(t *testing.T) {
 | |
| 	ctx, fnCancel := context.WithCancel(context.Background())
 | |
| 	defer fnCancel()
 | |
| 
 | |
| 	s := NewSchedulerCycle(ctx, 1*time.Millisecond)
 | |
| 
 | |
| 	s.Delay(func(ctx context.Context) error {
 | |
| 		return nil
 | |
| 	})
 | |
| 	s.Delay(func(ctx context.Context) error {
 | |
| 		return job.ErrJobNotCompletedYet
 | |
| 	})
 | |
| 	j3 := s.Delay(func(ctx context.Context) error {
 | |
| 		return errors.New("errors")
 | |
| 	})
 | |
| 
 | |
| 	time.Sleep(2 * time.Millisecond)
 | |
| 
 | |
| 	assert.Equal(t, 3, s.Len())
 | |
| 	assert.Equal(t, job.Failed.String(), s.GetJobDetails(j3).State)
 | |
| }
 |