initial import
This commit is contained in:
37
core/threading/taskrunner_test.go
Normal file
37
core/threading/taskrunner_test.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package threading
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRoutinePool(t *testing.T) {
|
||||
times := 100
|
||||
pool := NewTaskRunner(runtime.NumCPU())
|
||||
|
||||
var counter int32
|
||||
var waitGroup sync.WaitGroup
|
||||
for i := 0; i < times; i++ {
|
||||
waitGroup.Add(1)
|
||||
pool.Schedule(func() {
|
||||
atomic.AddInt32(&counter, 1)
|
||||
waitGroup.Done()
|
||||
})
|
||||
}
|
||||
|
||||
waitGroup.Wait()
|
||||
|
||||
assert.Equal(t, times, int(counter))
|
||||
}
|
||||
|
||||
func BenchmarkRoutinePool(b *testing.B) {
|
||||
queue := NewTaskRunner(runtime.NumCPU())
|
||||
for i := 0; i < b.N; i++ {
|
||||
queue.Schedule(func() {
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user