From 9b0aacd07a8a8fdbeaa782a8580ef6d1fc15f158 Mon Sep 17 00:00:00 2001 From: "cai.zhang" Date: Mon, 13 Sep 2021 11:58:11 +0800 Subject: [PATCH] Increase code coverage rate for proxy (#7727) Signed-off-by: cai.zhang --- internal/proxy/channels_mgr_test.go | 28 +++++++++++++++++++++++++++ internal/proxy/util_test.go | 30 +++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/internal/proxy/channels_mgr_test.go b/internal/proxy/channels_mgr_test.go index bb2da0bde4..6a41e16546 100644 --- a/internal/proxy/channels_mgr_test.go +++ b/internal/proxy/channels_mgr_test.go @@ -12,6 +12,7 @@ package proxy import ( + "sync" "testing" "github.com/milvus-io/milvus/internal/util/uniquegenerator" @@ -209,3 +210,30 @@ func TestChannelsMgrImpl_removeAllDQLMsgStream(t *testing.T) { assert.Equal(t, nil, err) } } + +func TestGetAllKeysAndGetAllValues(t *testing.T) { + chanMapping := make(map[vChan]pChan) + chanMapping["v1"] = "p1" + chanMapping["v2"] = "p2" + + t.Run("getAllKeys", func(t *testing.T) { + vChans := getAllKeys(chanMapping) + assert.Equal(t, 2, len(vChans)) + }) + + t.Run("getAllValues", func(t *testing.T) { + pChans := getAllValues(chanMapping) + assert.Equal(t, 2, len(pChans)) + }) +} + +func TestDeleteVChansByVID(t *testing.T) { + mgr := singleTypeChannelsMgr{ + id2vchansMtx: sync.RWMutex{}, + id2vchans: map[int][]vChan{ + 10: {"v1"}, + }, + } + + mgr.deleteVChansByVID(10) +} diff --git a/internal/proxy/util_test.go b/internal/proxy/util_test.go index 169698e1be..a19636e60d 100644 --- a/internal/proxy/util_test.go +++ b/internal/proxy/util_test.go @@ -75,3 +75,33 @@ func TestGetAttrByKeyFromRepeatedKV(t *testing.T) { assert.Equal(t, test.errIsNil, err == nil) } } + +func TestUtil(t *testing.T) { + a, b := 1, 2 + t.Run("getMax", func(t *testing.T) { + ans := getMax(a, b) + assert.Equal(t, b, ans) + + ans = getMax(b, a) + assert.Equal(t, b, ans) + }) + + t.Run("getMin", func(t *testing.T) { + ans := getMin(a, b) + assert.Equal(t, a, ans) + + ans = getMin(b, a) + assert.Equal(t, a, ans) + }) +} + +func TestGetPulsarConfig_Error(t *testing.T) { + protocol := "http" + ip := "pulsar" + port := "17777" + url := "/admin/v2/brokers/configuration/runtime" + + ret, err := GetPulsarConfig(protocol, ip, port, url) + assert.NotNil(t, err) + assert.Nil(t, ret) +}