github.com/lingyao2333/mo-zero@v1.4.1/core/executors/delayexecutor_test.go (about)

     1  package executors
     2  
     3  import (
     4  	"sync/atomic"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  func TestDelayExecutor(t *testing.T) {
    12  	var count int32
    13  	ex := NewDelayExecutor(func() {
    14  		atomic.AddInt32(&count, 1)
    15  	}, time.Millisecond*10)
    16  	for i := 0; i < 100; i++ {
    17  		ex.Trigger()
    18  	}
    19  	time.Sleep(time.Millisecond * 100)
    20  	assert.Equal(t, int32(1), atomic.LoadInt32(&count))
    21  }