github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/gossip/status_test.go (about)

     1  // Copyright 2018 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package gossip
    12  
    13  import (
    14  	"testing"
    15  
    16  	"github.com/cockroachdb/cockroach/pkg/util/leaktest"
    17  )
    18  
    19  func TestGossipStatus(t *testing.T) {
    20  	defer leaktest.AfterTest(t)()
    21  
    22  	ss := ServerStatus{
    23  		ConnStatus: []ConnStatus{
    24  			{NodeID: 1, Address: "localhost:1234", AgeNanos: 17e9},
    25  			{NodeID: 4, Address: "localhost:4567", AgeNanos: 18e9},
    26  		},
    27  		MaxConns: 3,
    28  		MetricSnap: MetricSnap{
    29  			BytesReceived: 1000,
    30  			BytesSent:     2000,
    31  			InfosReceived: 10,
    32  			InfosSent:     20,
    33  			ConnsRefused:  17,
    34  		},
    35  	}
    36  	if exp, act := `gossip server (2/3 cur/max conns, infos 20/10 sent/received, bytes 2000B/1000B sent/received, refused 17 conns)
    37    1: localhost:1234 (17s)
    38    4: localhost:4567 (18s)
    39  `, ss.String(); exp != act {
    40  		t.Errorf("expected:\n%q\ngot:\n%q", exp, act)
    41  	}
    42  
    43  	cs := ClientStatus{
    44  		ConnStatus: []OutgoingConnStatus{
    45  			{
    46  				ConnStatus: ss.ConnStatus[0],
    47  				MetricSnap: MetricSnap{BytesReceived: 77, BytesSent: 88, InfosReceived: 11, InfosSent: 22},
    48  			},
    49  		},
    50  		MaxConns: 3,
    51  	}
    52  	if exp, act := `gossip client (1/3 cur/max conns)
    53    1: localhost:1234 (17s: infos 22/11 sent/received, bytes 88B/77B sent/received)
    54  `, cs.String(); exp != act {
    55  		t.Errorf("expected:\n%q\ngot:\n%q", exp, act)
    56  	}
    57  
    58  }