(t *testing.T)
| 133 | } |
| 134 | |
| 135 | func TestSwitches(t *testing.T) { |
| 136 | s1, s2 := MakeSwitchPair(t, initSwitchFunc) |
| 137 | t.Cleanup(func() { |
| 138 | if err := s1.Stop(); err != nil { |
| 139 | t.Error(err) |
| 140 | } |
| 141 | }) |
| 142 | t.Cleanup(func() { |
| 143 | if err := s2.Stop(); err != nil { |
| 144 | t.Error(err) |
| 145 | } |
| 146 | }) |
| 147 | |
| 148 | if s1.Peers().Size() != 1 { |
| 149 | t.Errorf("expected exactly 1 peer in s1, got %v", s1.Peers().Size()) |
| 150 | } |
| 151 | if s2.Peers().Size() != 1 { |
| 152 | t.Errorf("expected exactly 1 peer in s2, got %v", s2.Peers().Size()) |
| 153 | } |
| 154 | |
| 155 | // Lets send some messages |
| 156 | ch0Msg := &p2pproto.PexAddrs{ |
| 157 | Addrs: []p2pproto.NetAddress{ |
| 158 | { |
| 159 | ID: "1", |
| 160 | }, |
| 161 | }, |
| 162 | } |
| 163 | ch1Msg := &p2pproto.PexAddrs{ |
| 164 | Addrs: []p2pproto.NetAddress{ |
| 165 | { |
| 166 | ID: "1", |
| 167 | }, |
| 168 | }, |
| 169 | } |
| 170 | ch2Msg := &p2pproto.PexAddrs{ |
| 171 | Addrs: []p2pproto.NetAddress{ |
| 172 | { |
| 173 | ID: "2", |
| 174 | }, |
| 175 | }, |
| 176 | } |
| 177 | s1.BroadcastEnvelope(Envelope{ChannelID: byte(0x00), Message: ch0Msg}) |
| 178 | s1.BroadcastEnvelope(Envelope{ChannelID: byte(0x01), Message: ch1Msg}) |
| 179 | s1.BroadcastEnvelope(Envelope{ChannelID: byte(0x02), Message: ch2Msg}) |
| 180 | assertMsgReceivedWithTimeout(t, |
| 181 | ch0Msg, |
| 182 | byte(0x00), |
| 183 | s2.Reactor("foo").(*TestReactor), 200*time.Millisecond, 5*time.Second) |
| 184 | assertMsgReceivedWithTimeout(t, |
| 185 | ch1Msg, |
| 186 | byte(0x01), |
| 187 | s2.Reactor("foo").(*TestReactor), 200*time.Millisecond, 5*time.Second) |
| 188 | assertMsgReceivedWithTimeout(t, |
| 189 | ch2Msg, |
| 190 | byte(0x02), |
| 191 | s2.Reactor("bar").(*TestReactor), 200*time.Millisecond, 5*time.Second) |
| 192 | } |
nothing calls this directly
no test coverage detected