github.com/prebid/prebid-server/v2@v2.18.0/util/task/func_runner_test.go (about)

     1  package task
     2  
     3  import (
     4  	"sync"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestNewTickerTaskFromFunc(t *testing.T) {
    12  	var runCountMutex sync.Mutex
    13  	runCount := 0
    14  
    15  	funcTest := func() error {
    16  		runCountMutex.Lock()
    17  		defer runCountMutex.Unlock()
    18  		runCount++
    19  		return nil
    20  	}
    21  
    22  	anyDuration := 1 * time.Hour // not used for this test
    23  	task := NewTickerTaskFromFunc(anyDuration, funcTest)
    24  
    25  	err := task.runner.Run()
    26  	assert.NoError(t, err)
    27  	assert.Equal(t, 1, runCount)
    28  }