(t *testing.T)
| 35 | const PubKeyStorePath = "./public.keystore" |
| 36 | |
| 37 | func 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 | } |
nothing calls this directly
no test coverage detected