tendermint/peer/connection_test.go

53 lines
1.1 KiB
Go
Raw Normal View History

2014-06-18 20:48:32 -07:00
package peer
import (
2014-06-25 21:37:20 -07:00
. "github.com/tendermint/tendermint/binary"
2014-06-18 20:48:32 -07:00
"testing"
2014-06-24 17:28:40 -07:00
"time"
2014-06-18 20:48:32 -07:00
)
func TestLocalConnection(t *testing.T) {
2014-06-24 17:28:40 -07:00
c1 := NewClient(func(conn *Connection) *Peer {
p := &Peer{conn: conn}
2014-06-18 20:48:32 -07:00
2014-06-24 17:28:40 -07:00
ch1 := NewChannel(String("ch1"),
nil,
// XXX these channels should be buffered.
2014-06-25 21:37:20 -07:00
make(chan Msg),
make(chan Msg),
2014-06-24 17:28:40 -07:00
)
ch2 := NewChannel(String("ch2"),
nil,
2014-06-25 21:37:20 -07:00
make(chan Msg),
make(chan Msg),
2014-06-24 17:28:40 -07:00
)
channels := make(map[String]*Channel)
2014-06-25 21:37:20 -07:00
channels[ch1.Name()] = ch1
channels[ch2.Name()] = ch2
2014-06-24 17:28:40 -07:00
p.channels = channels
return p
})
// XXX make c2 like c1.
c2 := NewClient(func(conn *Connection) *Peer {
return nil
})
// XXX clients don't have "local addresses"
2014-06-18 20:48:32 -07:00
c1.ConnectTo(c2.LocalAddress())
2014-06-24 17:28:40 -07:00
// lets send a message from c1 to c2.
c1.Broadcast(String(""), String("message"))
time.Sleep(500 * time.Millisecond)
2014-06-25 21:37:20 -07:00
inMsg := c2.PopMessage(String(""))
2014-06-24 17:28:40 -07:00
2014-06-18 20:48:32 -07:00
c1.Stop()
c2.Stop()
}