mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-02 20:09:57 +08:00
d2bc4a53be
issue: #33285 - use reader but not consumer for pulsar - advanced test framework - move some streaming related package into pkg --------- Signed-off-by: chyezh <chyezh@outlook.com>
49 lines
938 B
Go
49 lines
938 B
Go
package registry
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/milvus-io/milvus/pkg/mocks/streaming/mock_walimpls"
|
|
)
|
|
|
|
func TestRegister(t *testing.T) {
|
|
name := "mock"
|
|
b := mock_walimpls.NewMockOpenerBuilderImpls(t)
|
|
b.EXPECT().Name().Return(name)
|
|
|
|
RegisterBuilder(b)
|
|
b2 := MustGetBuilder(name)
|
|
assert.Equal(t, b.Name(), b2.Name())
|
|
|
|
// Panic if register twice.
|
|
assert.Panics(t, func() {
|
|
RegisterBuilder(b)
|
|
})
|
|
|
|
// Panic if get not exist builder.
|
|
assert.Panics(t, func() {
|
|
MustGetBuilder("not exist")
|
|
})
|
|
|
|
// Test concurrent.
|
|
wg := sync.WaitGroup{}
|
|
count := 10
|
|
wg.Add(count)
|
|
for i := 0; i < count; i++ {
|
|
go func(i int) {
|
|
defer wg.Done()
|
|
name := fmt.Sprintf("mock_%d", i)
|
|
b := mock_walimpls.NewMockOpenerBuilderImpls(t)
|
|
b.EXPECT().Name().Return(name)
|
|
RegisterBuilder(b)
|
|
b2 := MustGetBuilder(name)
|
|
assert.Equal(t, b.Name(), b2.Name())
|
|
}(i)
|
|
}
|
|
wg.Wait()
|
|
}
|