Commit 92f049e
committed
tests: add tests for HTTP tracker core events comparison
This test has been added becuase this code was not working:
```rust
let mut announced_peer = peer_copy;
announced_peer.peer_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
let mut added_peer = peer;
added_peer.peer_addr = SocketAddr::new(
IpAddr::V6(Ipv6Addr::new(0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969)),
8080,
);
let mut http_stats_event_sender_mock = MockHttpStatsEventSender::new();
http_stats_event_sender_mock
.expect_send_event()
.with(eq(Event::TcpAnnounce {
connection: ConnectionContext::new(
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
Some(8080),
server_service_binding,
),
announced_peer: peer,
added_peer: peer,
}))
.times(1)
.returning(|_| Box::pin(future::ready(Some(Ok(1)))));
```
using the same events:
Event sent:
TcpAnnounce { connection: ConnectionContext { client: ClientConnectionContext { ip_addr: 127.0.0.1, port: Some(8080) }, server: ServerConnectionContext { service_binding: ServiceBinding { protocol: HTTP, bind_address: 127.0.0.1:7070 } } }, announced_peer: Peer { peer_id: PeerId([45, 113, 66, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48]), peer_addr: 127.0.0.1:8080, updated: 1745316858.487824645s, uploaded: NumberOfBytes(I64(0)), downloaded: NumberOfBytes(I64(0)), left: NumberOfBytes(I64(0)), event: Started }, added_peer: Peer { peer_id: PeerId([45, 113, 66, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48]), peer_addr: [6969:6969:6969:6969:6969:6969:6969:6969]:8080, updated: 1745316858.487824645s, uploaded: NumberOfBytes(I64(0)), downloaded: NumberOfBytes(I64(0)), left: NumberOfBytes(I64(0)), event: Started } }
Event expected in the mock:
TcpAnnounce { connection: ConnectionContext { client: ClientConnectionContext { ip_addr: 127.0.0.1, port: Some(8080) }, server: ServerConnectionContext { service_binding: ServiceBinding { protocol: HTTP, bind_address: 127.0.0.1:7070 } } }, announced_peer: Peer { peer_id: PeerId([45, 113, 66, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48]), peer_addr: 127.0.0.1:8080, updated: 1745316858.487824645s, uploaded: NumberOfBytes(I64(0)), downloaded: NumberOfBytes(I64(0)), left: NumberOfBytes(I64(0)), event: Started }, added_peer: Peer { peer_id: PeerId([45, 113, 66, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48]), peer_addr: [6969:6969:6969:6969:6969:6969:6969:6969]:8080, updated: 1745316858.487824645s, uploaded: NumberOfBytes(I64(0)), downloaded: NumberOfBytes(I64(0)), left: NumberOfBytes(I64(0)), event: Started } }
That's one of the reasons why the expectation was changed. The other
reason is the only relevant part for the peer in the test is the updated peer
address.1 parent 4566ad5 commit 92f049e
1 file changed
Lines changed: 41 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
0 commit comments