github.com/yandex/pandora@v0.5.32/core/coreutil/schedule_test.go (about)

     1  package coreutil
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/stretchr/testify/require"
     8  	"github.com/yandex/pandora/core/schedule"
     9  )
    10  
    11  func TestCallbackOnFinishSchedule(t *testing.T) {
    12  	var callbackTimes int
    13  	wrapped := schedule.NewOnce(1)
    14  	testee := NewCallbackOnFinishSchedule(wrapped, func() {
    15  		callbackTimes++
    16  	})
    17  	startAt := time.Now()
    18  	testee.Start(startAt)
    19  	tx, ok := testee.Next()
    20  
    21  	require.True(t, ok)
    22  	require.Equal(t, startAt, tx)
    23  	require.Equal(t, 0, callbackTimes)
    24  
    25  	tx, ok = testee.Next()
    26  	require.False(t, ok)
    27  	require.Equal(t, startAt, tx)
    28  	require.Equal(t, 1, callbackTimes)
    29  
    30  	tx, ok = testee.Next()
    31  	require.False(t, ok)
    32  	require.Equal(t, startAt, tx)
    33  	require.Equal(t, 1, callbackTimes)
    34  }