mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-07 01:28:27 +08:00
Use embed etcd for allocator ut (#20749)
Signed-off-by: Congqi Xia <congqi.xia@zilliz.com> Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
This commit is contained in:
parent
c761de19bc
commit
e35b523a99
@ -17,23 +17,65 @@
|
|||||||
package allocator
|
package allocator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/milvus-io/milvus/internal/util/etcd"
|
|
||||||
"github.com/milvus-io/milvus/internal/util/paramtable"
|
"github.com/milvus-io/milvus/internal/util/paramtable"
|
||||||
"github.com/milvus-io/milvus/internal/util/tsoutil"
|
"github.com/milvus-io/milvus/internal/util/tsoutil"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"go.etcd.io/etcd/server/v3/embed"
|
||||||
|
"go.etcd.io/etcd/server/v3/etcdserver/api/v3client"
|
||||||
)
|
)
|
||||||
|
|
||||||
var gTestIDAllocator *GlobalIDAllocator
|
var gTestIDAllocator *GlobalIDAllocator
|
||||||
|
|
||||||
var Params paramtable.ComponentParam
|
var Params paramtable.ComponentParam
|
||||||
|
|
||||||
|
var embedEtcdServer *embed.Etcd
|
||||||
|
|
||||||
|
func startEmbedEtcdServer() (*embed.Etcd, error) {
|
||||||
|
dir, err := ioutil.TempDir(os.TempDir(), "milvus_ut")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
config := embed.NewConfig()
|
||||||
|
|
||||||
|
config.Dir = dir
|
||||||
|
config.LogLevel = "warn"
|
||||||
|
config.LogOutputs = []string{"default"}
|
||||||
|
u, err := url.Parse("http://localhost:0")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
config.LCUrls = []url.URL{*u}
|
||||||
|
u, err = url.Parse("http://localhost:0")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
config.LPUrls = []url.URL{*u}
|
||||||
|
|
||||||
|
return embed.StartEtcd(config)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
var err error
|
||||||
|
// init embed etcd
|
||||||
|
embedEtcdServer, err = startEmbedEtcdServer()
|
||||||
|
if err != nil {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
defer embedEtcdServer.Close()
|
||||||
|
|
||||||
|
exitCode := m.Run()
|
||||||
|
if exitCode > 0 {
|
||||||
|
os.Exit(exitCode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestGlobalTSOAllocator_All(t *testing.T) {
|
func TestGlobalTSOAllocator_All(t *testing.T) {
|
||||||
Params.Init()
|
etcdCli := v3client.New(embedEtcdServer.Server)
|
||||||
etcdCli, err := etcd.GetEtcdClient(&Params.EtcdCfg)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
defer etcdCli.Close()
|
|
||||||
etcdKV := tsoutil.NewTSOKVBase(etcdCli, "/test/root/kv", "gidTest")
|
etcdKV := tsoutil.NewTSOKVBase(etcdCli, "/test/root/kv", "gidTest")
|
||||||
|
|
||||||
gTestIDAllocator = NewGlobalIDAllocator("idTimestamp", etcdKV)
|
gTestIDAllocator = NewGlobalIDAllocator("idTimestamp", etcdKV)
|
||||||
@ -67,6 +109,5 @@ func TestGlobalTSOAllocator_All(t *testing.T) {
|
|||||||
id2, err := gTestIDAllocator.allocator.GenerateTSO(count2)
|
id2, err := gTestIDAllocator.allocator.GenerateTSO(count2)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, id2-id1, uint64(count2))
|
assert.Equal(t, id2-id1, uint64(count2))
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user