milvus/internal/indexcoord/metrics_info_test.go
godchen bb7a0766fe
Add dependency factory (#16204)
Signed-off-by: godchen0212 <qingxiang.chen@zilliz.com>
2022-04-07 22:05:32 +08:00

83 lines
2.3 KiB
Go

// Licensed to the LF AI & Data foundation under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package indexcoord
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/milvus-io/milvus/internal/indexnode"
"github.com/milvus-io/milvus/internal/util/dependency"
"github.com/milvus-io/milvus/internal/util/etcd"
"github.com/milvus-io/milvus/internal/util/metricsinfo"
)
func TestGetSystemInfoMetrics(t *testing.T) {
ctx := context.Background()
factory := dependency.NewDefaultFactory(true)
ic, err := NewIndexCoord(ctx, factory)
assert.Nil(t, err)
Params.Init()
etcdCli, err := etcd.GetEtcdClient(&Params.EtcdCfg)
defer etcdCli.Close()
assert.NoError(t, err)
ic.SetEtcdClient(etcdCli)
err = ic.Init()
assert.Nil(t, err)
err = ic.Start()
assert.Nil(t, err)
err = ic.Register()
assert.Nil(t, err)
t.Run("getSystemInfoMetrics", func(t *testing.T) {
req, err := metricsinfo.ConstructRequestByMetricType(metricsinfo.SystemInfoMetrics)
assert.Nil(t, err)
resp, err := getSystemInfoMetrics(ctx, req, ic)
assert.Nil(t, err)
assert.NotNil(t, resp)
})
t.Run("getSystemInfoMetrics error", func(t *testing.T) {
req, err := metricsinfo.ConstructRequestByMetricType(metricsinfo.SystemInfoMetrics)
assert.Nil(t, err)
inm1 := &indexnode.Mock{
Failure: true,
Err: true,
}
inm2 := &indexnode.Mock{
Failure: true,
Err: false,
}
ic.nodeManager.setClient(1, inm1)
ic.nodeManager.setClient(2, inm2)
resp, err := getSystemInfoMetrics(ctx, req, ic)
assert.Nil(t, err)
assert.NotNil(t, resp)
})
err = ic.Stop()
assert.Nil(t, err)
}