github.com/benz9527/toy-box/algo@v0.0.0-20240221120937-66c0c6bd5abd/timer/x_event_test.go (about)

     1  package timer
     2  
     3  import (
     4  	"github.com/stretchr/testify/assert"
     5  	"testing"
     6  )
     7  
     8  func TestNewTimingWheelEventsPool(t *testing.T) {
     9  	pool := newTimingWheelEventsPool()
    10  	if pool == nil {
    11  		t.Fatal("pool is nil")
    12  	}
    13  	event := pool.Get()
    14  	event.AddTask(&task{
    15  		jobMetadata: &jobMetadata{
    16  			jobID: "1",
    17  		},
    18  	})
    19  	task, ok := event.GetTask()
    20  	assert.True(t, ok)
    21  	assert.Equal(t, JobID("1"), task.GetJobID())
    22  	jobID, ok := event.GetCancelTaskJobID()
    23  	assert.False(t, ok)
    24  	pool.Put(event)
    25  
    26  	event = pool.Get()
    27  	event.CancelTaskJobID("2")
    28  	jobID, ok = event.GetCancelTaskJobID()
    29  	assert.True(t, ok)
    30  	assert.Equal(t, JobID("2"), jobID)
    31  }