milvus/internal/querycoordv2/observers/task_dispatcher_test.go
congqixia 709594f158
enhance: [2.5] Use v2 package name for pkg module (#40117)
Cherry-pick from master
pr: #39990
Related to #39095

https://go.dev/doc/modules/version-numbers

Update pkg version according to golang dep version convention

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
2025-02-23 00:46:01 +08:00

47 lines
898 B
Go

package observers
import (
"context"
"sync"
"testing"
"time"
"github.com/stretchr/testify/suite"
"github.com/milvus-io/milvus/pkg/v2/util/paramtable"
"github.com/milvus-io/milvus/pkg/v2/util/typeutil"
)
type taskDispatcherSuite struct {
suite.Suite
}
func (s *taskDispatcherSuite) SetupSuite() {
paramtable.Get().Init(paramtable.NewBaseTable())
}
func (s *taskDispatcherSuite) TestMultipleSubmit() {
var wg sync.WaitGroup
wg.Add(6)
set := typeutil.NewConcurrentSet[int64]()
dispatcher := newTaskDispatcher(func(ctx context.Context, key int64) {
defer wg.Done()
set.Insert(key)
time.Sleep(time.Second)
})
dispatcher.Start()
dispatcher.AddTask(1, 2, 3, 4, 5)
dispatcher.AddTask(2, 3, 4, 5, 6)
wg.Wait()
s.ElementsMatch([]int64{1, 2, 3, 4, 5, 6}, set.Collect())
dispatcher.Stop()
}
func TestTaskDispatcher(t *testing.T) {
suite.Run(t, new(taskDispatcherSuite))
}