forked from milvus-io/milvus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats_updater_test.go
64 lines (50 loc) · 1.34 KB
/
stats_updater_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
package datanode
import (
"testing"
"github.com/cockroachdb/errors"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite"
"github.com/milvus-io/milvus/pkg/mq/msgstream"
"github.com/milvus-io/milvus/pkg/util/tsoutil"
)
type MqStatsUpdaterSuite struct {
suite.Suite
producer *msgstream.MockMsgStream
updater *mqStatsUpdater
}
func (s *MqStatsUpdaterSuite) SetupTest() {
s.producer = msgstream.NewMockMsgStream(s.T())
s.updater = &mqStatsUpdater{
stats: make(map[int64]int64),
producer: s.producer,
config: &nodeConfig{
vChannelName: "by-dev-rootcoord-dml_0v0",
},
}
}
func (s *MqStatsUpdaterSuite) TestSend() {
s.Run("send_ok", func() {
s.producer.EXPECT().Produce(mock.Anything).Return(nil)
s.updater.mut.Lock()
s.updater.stats[100] = 1024
s.updater.mut.Unlock()
err := s.updater.send(tsoutil.GetCurrentTime(), []int64{100})
s.NoError(err)
s.updater.mut.Lock()
_, has := s.updater.stats[100]
s.updater.mut.Unlock()
s.False(has)
})
s.Run("send_error", func() {
s.SetupTest()
s.producer.EXPECT().Produce(mock.Anything).Return(errors.New("mocked"))
s.updater.mut.Lock()
s.updater.stats[100] = 1024
s.updater.mut.Unlock()
err := s.updater.send(tsoutil.GetCurrentTime(), []int64{100})
s.Error(err)
})
}
func TestMqStatsUpdater(t *testing.T) {
suite.Run(t, new(MqStatsUpdaterSuite))
}