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