Files
wehub-resource-sync 498b235461
Build and test / Build and test AMD64 Ubuntu 22.04 (push) Failing after 0s
Publish Builder / amazonlinux2023 (push) Failing after 1s
Build and test / UT for Go (push) Has been skipped
Publish KRTE Images / KRTE (push) Failing after 1s
Build and test / Integration Test (push) Has been skipped
Build and test / Upload Code Coverage (push) Has been skipped
Publish Builder / rockylinux9 (push) Failing after 1s
Publish Builder / ubuntu22.04 (push) Failing after 0s
Publish Builder / ubuntu24.04 (push) Failing after 0s
Publish Gpu Builder / publish-gpu-builder (push) Failing after 1s
Publish Test Images / PyTest (push) Failing after 0s
Build and test / UT for Cpp (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:31:17 +08:00

68 lines
1.7 KiB
Go

package connection
import (
"context"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/milvus-io/milvus-proto/go-api/v3/commonpb"
"github.com/milvus-io/milvus/pkg/v3/util/paramtable"
)
func TestConnectionManager(t *testing.T) {
paramtable.Init()
pt := paramtable.Get()
pt.Save(pt.ProxyCfg.ConnectionCheckIntervalSeconds.Key, "2")
pt.Save(pt.ProxyCfg.ConnectionClientInfoTTLSeconds.Key, "1")
defer pt.Reset(pt.ProxyCfg.ConnectionCheckIntervalSeconds.Key)
defer pt.Reset(pt.ProxyCfg.ConnectionClientInfoTTLSeconds.Key)
s := newConnectionManager()
defer s.Stop()
s.Register(context.TODO(), 1, &commonpb.ClientInfo{
Reserved: map[string]string{"for_test": "for_test"},
})
assert.Equal(t, 1, len(s.List()))
// register duplicate.
s.Register(context.TODO(), 1, &commonpb.ClientInfo{})
assert.Equal(t, 1, len(s.List()))
s.Register(context.TODO(), 2, &commonpb.ClientInfo{})
assert.Equal(t, 2, len(s.List()))
s.KeepActive(1)
s.KeepActive(2)
time.Sleep(time.Millisecond * 5)
assert.Equal(t, 2, len(s.List()))
assert.Eventually(t, func() bool {
return len(s.List()) == 0
}, time.Second*5, time.Second)
}
func TestConnectionManager_Purge(t *testing.T) {
paramtable.Init()
pt := paramtable.Get()
pt.Save(pt.ProxyCfg.ConnectionCheckIntervalSeconds.Key, "2")
pt.Save(pt.ProxyCfg.MaxConnectionNum.Key, "2")
defer pt.Reset(pt.ProxyCfg.ConnectionCheckIntervalSeconds.Key)
defer pt.Reset(pt.ProxyCfg.MaxConnectionNum.Key)
s := newConnectionManager()
defer s.Stop()
repeat := 10
for i := 0; i < repeat; i++ {
s.Register(context.TODO(), int64(i), &commonpb.ClientInfo{})
}
assert.Eventually(t, func() bool {
return s.clientInfos.Len() <= 2
}, time.Second*5, time.Second)
}