diff --git a/connection.go b/connection.go index aa707b97..68b4e0b3 100644 --- a/connection.go +++ b/connection.go @@ -87,8 +87,6 @@ type MConnection struct { } func NewMConnection(config cfg.Config, conn net.Conn, chDescs []*ChannelDescriptor, onReceive receiveCbFunc, onError errorCbFunc) *MConnection { - setConfigDefaults(config) - mconn := &MConnection{ conn: conn, bufReader: bufio.NewReaderSize(conn, minReadBufferSize), diff --git a/switch.go b/switch.go index 3cb5f5c9..921dcf98 100644 --- a/switch.go +++ b/switch.go @@ -181,8 +181,8 @@ func (sw *Switch) OnStop() { // Stop peers for _, peer := range sw.peers.List() { peer.Stop() + sw.peers.Remove(peer) } - sw.peers = NewPeerSet() // Stop reactors for _, reactor := range sw.reactors { reactor.Stop() diff --git a/switch_test.go b/switch_test.go index 783d2fd9..e46d0f85 100644 --- a/switch_test.go +++ b/switch_test.go @@ -76,6 +76,12 @@ func (tr *TestReactor) Receive(chID byte, peer *Peer, msgBytes []byte) { } } +func (tr *TestReactor) getMsgs(chID byte) []PeerMessage { + tr.mtx.Lock() + defer tr.mtx.Unlock() + return tr.msgsReceived[chID] +} + //----------------------------------------------------------------------------- // convenience method for creating two switches connected to each other. @@ -170,7 +176,7 @@ func TestSwitches(t *testing.T) { time.Sleep(5000 * time.Millisecond) // Check message on ch0 - ch0Msgs := s2.Reactor("foo").(*TestReactor).msgsReceived[byte(0x00)] + ch0Msgs := s2.Reactor("foo").(*TestReactor).getMsgs(byte(0x00)) if len(ch0Msgs) != 1 { t.Errorf("Expected to have received 1 message in ch0") } @@ -179,7 +185,7 @@ func TestSwitches(t *testing.T) { } // Check message on ch1 - ch1Msgs := s2.Reactor("foo").(*TestReactor).msgsReceived[byte(0x01)] + ch1Msgs := s2.Reactor("foo").(*TestReactor).getMsgs(byte(0x01)) if len(ch1Msgs) != 1 { t.Errorf("Expected to have received 1 message in ch1") } @@ -188,7 +194,7 @@ func TestSwitches(t *testing.T) { } // Check message on ch2 - ch2Msgs := s2.Reactor("bar").(*TestReactor).msgsReceived[byte(0x02)] + ch2Msgs := s2.Reactor("bar").(*TestReactor).getMsgs(byte(0x02)) if len(ch2Msgs) != 1 { t.Errorf("Expected to have received 1 message in ch2") }