You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.1 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. package peer
  2. import (
  3. . "github.com/tendermint/tendermint/binary"
  4. "testing"
  5. "time"
  6. )
  7. func TestLocalConnection(t *testing.T) {
  8. c1 := NewClient(func(conn *Connection) *Peer {
  9. p := &Peer{conn: conn}
  10. ch1 := NewChannel(String("ch1"),
  11. nil,
  12. // XXX these channels should be buffered.
  13. make(chan Msg),
  14. make(chan Msg),
  15. )
  16. ch2 := NewChannel(String("ch2"),
  17. nil,
  18. make(chan Msg),
  19. make(chan Msg),
  20. )
  21. channels := make(map[String]*Channel)
  22. channels[ch1.Name()] = ch1
  23. channels[ch2.Name()] = ch2
  24. p.channels = channels
  25. return p
  26. })
  27. // XXX make c2 like c1.
  28. c2 := NewClient(func(conn *Connection) *Peer {
  29. return nil
  30. })
  31. // XXX clients don't have "local addresses"
  32. c1.ConnectTo(c2.LocalAddress())
  33. // lets send a message from c1 to c2.
  34. c1.Broadcast(String(""), String("message"))
  35. time.Sleep(500 * time.Millisecond)
  36. inMsg := c2.PopMessage(String(""))
  37. c1.Stop()
  38. c2.Stop()
  39. }