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.

51 lines
1.1 KiB

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