MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / TestCollectClient_UploadMetrics

Function TestCollectClient_UploadMetrics

metric/rpc_test.go:37–83  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

35const PubKeyStorePath = "./public.keystore"
36
37func TestCollectClient_UploadMetrics(t *testing.T) {
38 defer utils.RemoveAll(PubKeyStorePath + "*")
39 log.SetLevel(log.DebugLevel)
40 addr := "127.0.0.1:0"
41 masterKey := []byte("abc")
42
43 cc := NewCollectClient()
44 cs := NewCollectServer()
45
46 server, err := rpc.NewServerWithService(rpc.ServiceMap{MetricServiceName: cs})
47 if err != nil {
48 log.Fatal(err)
49 }
50
51 route.NewDHTService(PubKeyStorePath, new(consistent.KMSStorage), false)
52 server.InitRPCServer(addr, "../keys/test.key", masterKey)
53 go server.Serve()
54
55 publicKey, err := kms.GetLocalPublicKey()
56 nonce := asymmetric.GetPubKeyNonce(publicKey, 10, 100*time.Millisecond, nil)
57 serverNodeID := proto.NodeID(nonce.Hash.String())
58 kms.SetPublicKey(serverNodeID, nonce.Nonce, publicKey)
59 kms.SetLocalNodeIDNonce(nonce.Hash.CloneBytes(), &nonce.Nonce)
60 route.SetNodeAddrCache(&proto.RawNodeID{Hash: nonce.Hash}, server.Listener.Addr().String())
61
62 Convey("get metric and upload by RPC", t, func() {
63 err = cc.UploadMetrics(serverNodeID)
64 v, ok := cs.NodeMetric.Load(serverNodeID)
65 So(ok, ShouldBeTrue)
66 //log.Debugf("NodeMetric:%#v", v)
67
68 m, _ := v.(SimpleMetricMap)
69 mfb, err := cc.GatherMetricBytes()
70 So(err, ShouldBeNil)
71 So(len(m), ShouldEqual, len(mfb))
72 So(len(m), ShouldBeGreaterThan, 2)
73 })
74
75 Convey("get metric and upload by simply called without node id", t, func() {
76 req := &proto.UploadMetricsReq{
77 MFBytes: nil,
78 Envelope: proto.Envelope{},
79 }
80 err = cs.UploadMetrics(req, &proto.UploadMetricsResp{})
81 So(err, ShouldNotBeNil)
82 })
83}

Callers

nothing calls this directly

Calls 15

UploadMetricsMethod · 0.95
GatherMetricBytesMethod · 0.95
UploadMetricsMethod · 0.95
RemoveAllFunction · 0.92
SetLevelFunction · 0.92
FatalFunction · 0.92
NewDHTServiceFunction · 0.92
GetLocalPublicKeyFunction · 0.92
GetPubKeyNonceFunction · 0.92
NodeIDTypeAlias · 0.92
SetPublicKeyFunction · 0.92
SetLocalNodeIDNonceFunction · 0.92

Tested by

no test coverage detected