metrics_info_test.go 2.0 KB
Newer Older
1 2 3 4 5 6
// 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
7 8
// with the License. You may obtain a copy of the License at
//
9
//     http://www.apache.org/licenses/LICENSE-2.0
10
//
11 12 13 14 15
// 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.
16 17 18 19

package indexcoord

import (
20
	"context"
21 22
	"testing"

23 24 25 26
	"github.com/milvus-io/milvus/internal/indexnode"

	"github.com/milvus-io/milvus/internal/util/metricsinfo"
	"github.com/stretchr/testify/assert"
27 28 29
)

func TestGetSystemInfoMetrics(t *testing.T) {
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
	ctx := context.Background()
	ic, err := NewIndexCoord(ctx)
	assert.Nil(t, err)
	Params.Init()
	err = ic.Register()
	assert.Nil(t, err)

	err = ic.Init()
	assert.Nil(t, err)
	err = ic.Start()
	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)
74
}