diff --git a/orderer/sbft/main/network_test.go b/orderer/sbft/main/network_test.go index 340d276e427..723ab61e7d0 100644 --- a/orderer/sbft/main/network_test.go +++ b/orderer/sbft/main/network_test.go @@ -45,14 +45,14 @@ const maindir = "github.com/hyperledger/fabric/orderer/sbft/main" var mainexe = os.TempDir() + "/" + "sbft" -type peer struct { +type Peer struct { id uint64 config flags cancel context.CancelFunc cmd *exec.Cmd } -type receiver struct { +type Receiver struct { id uint64 retch chan []byte signals chan bool @@ -193,7 +193,7 @@ func TestTenReplicasBombedWithBroadcastsIfLedgersConsistent(t *testing.T) { StartPeers(peers) defer StopPeers(peers) - receivers := make([]*receiver, 0, len(peers)) + receivers := make([]*Receiver, 0, len(peers)) for i := 0; i < len(peers); i++ { r, err := Receive(peers[i], startingPort) if err != nil { @@ -223,8 +223,8 @@ func TestTenReplicasBombedWithBroadcastsIfLedgersConsistent(t *testing.T) { } } -func InitPeers(num uint64, startingPort int) []*peer { - peers := make([]*peer, 0, num) +func InitPeers(num uint64, startingPort int) []*Peer { + peers := make([]*Peer, 0, num) certFiles := make([]string, 0, num) for i := uint64(0); i < num; i++ { certFiles = append(certFiles, generateCertificate(i, keyfile)) @@ -236,13 +236,13 @@ func InitPeers(num uint64, startingPort int) []*peer { return peers } -func StartPeers(peers []*peer) { +func StartPeers(peers []*Peer) { for _, p := range peers { p.start() } } -func StopPeers(peers []*peer) { +func StopPeers(peers []*Peer) { for _, p := range peers { p.stop() } @@ -275,7 +275,7 @@ func generateConfig(peerNum uint64, startingPort int, certFiles []string) string return conffilepath } -func initPeer(uid uint64, startingPort int, configFile string, certFile string) (p *peer) { +func initPeer(uid uint64, startingPort int, configFile string, certFile string) (p *Peer) { tempDir, err := ioutil.TempDir("", "sbft_test") panicOnError(err) os.RemoveAll(tempDir) @@ -286,7 +286,7 @@ func initPeer(uid uint64, startingPort int, configFile string, certFile string) keyFile: keyfile, dataDir: tempDir} ctx, cancel := context.WithCancel(context.Background()) - p = &peer{id: uid, cancel: cancel, config: c} + p = &Peer{id: uid, cancel: cancel, config: c} err = initInstance(c) panicOnError(err) p.cmd = exec.CommandContext(ctx, mainexe, "-addr", p.config.listenAddr, "-gaddr", p.config.grpcAddr, "-cert", p.config.certFile, "-key", @@ -296,17 +296,17 @@ func initPeer(uid uint64, startingPort int, configFile string, certFile string) return } -func (p *peer) start() { +func (p *Peer) start() { err := p.cmd.Start() panicOnError(err) } -func (p *peer) stop() { +func (p *Peer) stop() { p.cancel() p.cmd.Wait() } -func Broadcast(p *peer, startingPort int, bytes []byte) error { +func Broadcast(p *Peer, startingPort int, bytes []byte) error { timeout := 10 * time.Second grpcAddress := grpcAddress(p.id, startingPort) clientconn, err := grpc.Dial(grpcAddress, grpc.WithBlock(), grpc.WithTimeout(timeout), grpc.WithInsecure()) @@ -330,7 +330,7 @@ func Broadcast(p *peer, startingPort int, bytes []byte) error { return nil } -func Receive(p *peer, startingPort int) (*receiver, error) { +func Receive(p *Peer, startingPort int) (*Receiver, error) { retch := make(chan []byte, 100) signals := make(chan bool, 100) timeout := 4 * time.Second @@ -378,14 +378,14 @@ func Receive(p *peer, startingPort int) (*receiver, error) { } } }() - return &receiver{id: p.id, retch: retch, signals: signals}, nil + return &Receiver{id: p.id, retch: retch, signals: signals}, nil } -func (r *receiver) Received() int { +func (r *Receiver) Received() int { return len(r.retch) } -func (r *receiver) Stop() { +func (r *Receiver) Stop() { close(r.signals) } @@ -396,7 +396,7 @@ func AssertWithTimeout(assertion func() bool, timeoutSec int) bool { return assertion() } -func WaitForConnection(peers []*peer) { +func WaitForConnection(peers []*Peer) { l := len(peers) m := math.Max(float64(3), float64(l-3)) _ = <-time.After(time.Duration(m) * time.Second) diff --git a/orderer/sbft/main/sbft_test.go b/orderer/sbft/main/sbft_test.go index 792e5c8f846..9fc4e54de4a 100644 --- a/orderer/sbft/main/sbft_test.go +++ b/orderer/sbft/main/sbft_test.go @@ -34,11 +34,11 @@ import ( var logger = logging.MustGetLogger("sbft_test") -var UPDATE byte = 0 -var SEND byte = 1 +const update byte = 0 +const sent byte = 1 -var NEEDED_UPDATES = 2 -var NEEDED_SENT = 1 +const neededUpdates = 2 +const neededSent = 1 func TestSbftPeer(t *testing.T) { t.Parallel() @@ -108,18 +108,18 @@ func checkResults(t *testing.T, resultch chan byte, errorch chan error) { select { case result := <-resultch: switch result { - case UPDATE: + case update: updates++ - case SEND: + case sent: sentBroadcast++ } case <-time.After(30 * time.Second): continue } } - if updates != NEEDED_UPDATES { + if updates != neededUpdates { t.Errorf("We did not get all the ledger updates.") - } else if sentBroadcast != NEEDED_SENT { + } else if sentBroadcast != neededSent { t.Errorf("We were unable to send all the broadcasts.") } else { logger.Info("Successfully sent and received everything.") @@ -162,7 +162,7 @@ func updateReceiver(t *testing.T, resultch chan byte, errorch chan error, client logger.Infof("{Update Receiver} %d - %v", i+1, pl.Data) } } - resultch <- UPDATE + resultch <- update } logger.Info("{Update Receiver} Exiting...") } @@ -184,5 +184,5 @@ func broadcastSender(t *testing.T, resultch chan byte, errorch chan error, clien bstream.Send(&cb.Envelope{Payload: mpl}) logger.Infof("{Broadcast Sender} Broadcast sent: %v", bs) logger.Info("{Broadcast Sender} Exiting...") - resultch <- SEND + resultch <- sent }