milvus/internal/datanode/io_pool_test.go
Jiquan Long 579c50fa1a
Fix io pool goroutine leakage (#19892)
Signed-off-by: longjiquan <jiquan.long@zilliz.com>

Signed-off-by: longjiquan <jiquan.long@zilliz.com>
2022-10-19 18:23:27 +08:00

38 lines
814 B
Go

package datanode
import (
"sync"
"testing"
"github.com/stretchr/testify/assert"
"github.com/milvus-io/milvus/internal/util/concurrency"
)
func Test_getOrCreateIOPool(t *testing.T) {
Params.InitOnce()
ioConcurrency := Params.DataNodeCfg.IOConcurrency
Params.DataNodeCfg.IOConcurrency = 64
defer func() { Params.DataNodeCfg.IOConcurrency = ioConcurrency }()
nP := 10
nTask := 10
wg := sync.WaitGroup{}
for i := 0; i < nP; i++ {
wg.Add(1)
go func() {
defer wg.Done()
p := getOrCreateIOPool()
futures := make([]*concurrency.Future, 0, nTask)
for j := 0; j < nTask; j++ {
future := p.Submit(func() (interface{}, error) {
return nil, nil
})
futures = append(futures, future)
}
err := concurrency.AwaitAll(futures...)
assert.NoError(t, err)
}()
}
wg.Wait()
}