Add a test peer that stands in for a remote node and drive the transport tests through it (#5284) * Add a test peer that stands in for a remote node Tests of the TCP server and listener wrote to tcp_socket objects borrowed from the node under test, parsed handshakes by hand, or started a second full node only to have something send a message. A borrowed socket runs on the node's io threads and counts into the node's stats, and a second node sends traffic of its own, so neither allows exact counts. nano::test::peer is a plain asio connection with a node id and nothing behind it. It connects to the node, completes the handshake when the test calls handshake (), sends only what the test tells it to and keeps every message the node sends it, read by a thread of its own and parsed with the production deserializer. Options set the node id, protocol version and capabilities it presents. A test can also send bytes that form no message, or do the handshake by hand with handshake_response (). nano::test::peer_listener covers the connections the node opens. It listens on a loopback port that a test points the node at, by peer merging or a direct connect, and accept () hands out each connection as a peer. A listener nobody accepts from still holds the node's connections open, which is all some tests need. * Drive the tcp_server tests through the test peer The handshake tests each repeated the connect and serialization setup around a borrowed tcp_socket, and one parsed the node's reply over fifty lines. They now connect a nano::test::peer, which also sees the node close the connection, so they no longer wait about a second for the listener to purge it. The tests that started a second node only to send a message send it from a peer instead, which leaves the node with no other inbound traffic and lets them assert exact counts. handshake_deserialization_failure and handshake_invalid_message_type_aborts stopped at the header type check without asserting it; they are renamed handshake_unknown_message_type and handshake_non_handshake_message and assert the invalid_message_type count. handshake_outdated_protocol_version and handshake_wrong_network_id appended a whole message, header included, as the payload of a hand-made header, and now send one well-formed message. handshake_incomplete_message asserts that the cut read is counted as a server error and not as an aborted handshake. rejects_publish_without_block_type sends its header on a realtime connection, where that check is the only one in its way. depeer_on_outdated_version repeated filter_invalid_version_using with one other assertion and is folded into it. handshake_success, handshake_flags_exchanged and handshake_peering_only_flag check both directions against one node: what its channel records about the peer, and what its own handshake message announces. handshake_query_after_reconnect takes both of its connections from one peer_listener instead of an acceptor on the node's io context. handshake_query_answered and realtime_largest_payload are new. They take over from tcp_listener.node_id_handshake, which read part of a reply and asserted only that no error occurred, and from tcp_listener.asc_pull_oversized_payload_no_crash, whose header was refused at the type check before any payload was read. * Drive the tcp_listener tests through the test peer The limit tests repeated the same client setup around borrowed tcp_socket objects, kept an unused port and never checked that a refused client sees its connection closed. They now connect peers in order and assert the refusal, the accept count and the closed connection. max_connections also checks that the waiting peer gets in once a slot frees, and max_peers_per_ip, which tested the flag that disables the limit, is renamed max_connections_per_ip_disabled. The handshake timeout tests built their config from scratch instead of from the system's and only checked that the connection count fell to zero, which any close satisfies, and one of them built a tcp_channel by hand. They are renamed handshake_timeout and handshake_timeout_after_query, assert the handshake_timeout count and see the close from the peer's side. max_connections_excludes_outbound and reconnect_cooldown_outbound point the node at a peer_listener nobody accepts from instead of a bare acceptor. node_id_handshake and asc_pull_oversized_payload_no_crash are removed: tcp_server.handshake_query_answered and tcp_server.realtime_largest_payload cover what they meant to. * Drive network filter, purge and exclusion tests through the test peer The duplicate filter tests sent their messages from a second node and used a fixed pause to show that the first copy was not taken for a duplicate. With a peer as the only sender they wait for the first copy to be dispatched and assert exact counts instead. duplicate_revert_publish set a digest on its publish by hand and never checked that the block processor refused it. The half that carries a digest now comes from a peer, so the server computes the digest, and both halves assert the refusal. duplicate_revert_rejected_fork is new: a peer publishes one fork more than an election holds, the election turns it away and erases it from the filter, and the peer's next copy is received again, while a second copy of a held fork is caught as a duplicate. last_contacted needed three keepalives and a second node that refused inbound connections, to get around that node's own traffic and its reconnects. A peer sends one keepalive and the test counts one. cleanup_purge and the two purge_dead_channel tests only needed a connection to close, which a peer provides without the wait for two nodes to settle on one channel each. tcp_no_accept_excluded_peers uses a peer for the refused connection and a peer_listener for the endpoint the node will not reach out to. * Drive telemetry and rep crawler tests through the test peer rep_crawler.ignore_rebroadcasted sent the same rebroadcasted vote in a loop, of which the duplicate filter let only the first copy through, and then checked for a second that no representative appeared. It now sends one rebroadcasted vote, waits until it is processed and checks that it was not taken as an answer to the query. Then it sends a vote as the peer's own and checks that this one makes the peer a representative. telemetry.dos_tcp only required more than one of its ten requests to arrive. With a peer as the only sender it asserts all ten, and counts the acks the peer receives instead of the ones the node reports sending. telemetry.max_possible_size sends its ack from a peer as well. * Drive the peer_blocklist connection tests through the test peer The tests that refuse or drop a blocklisted peer used a second node as that peer and waited on both nodes' views of the connection. A peer gives the same connection under the node id the test chooses, sees the node close it and never redials, so disconnect_node_id no longer needs reachout disabled to keep the dropped node from coming back on its own. The outbound tests take the node's connection from a peer_listener. * Give the test peer's handshake a type and test the v2 format The peer built its handshake messages itself, always in the v3 format, and took the identity it presents as constructor options. Three tcp_server tests that sent v2 responses before they moved onto the peer had turned into v3 tests, among them the only one that completed a v2 handshake over TCP. That is the format of every node from before the capability exchange. nano::test::peer_handshake now holds a peer's side of the handshake: the node id it claims and the functions that build its query and its response. handshake_v3 () and handshake_v2 () make valid ones from the identity, protocol version and capabilities given, and peer.handshake () takes one, v3 by default. A peer has no options of its own any more. A test of a malformed handshake builds a message from a ready-made handshake, changes it and sends it itself, so handshake_outdated_protocol_version, handshake_wrong_network_id and handshake_self_connection_rejected show which message the node refuses. handshake_success_v2 completes a v2 handshake and checks that the node answers in v2 and records no capabilities, and handshake_cookie_per_connection has one peer in each format. handshake_records_remote_protocol_version uses v2, as a peer on the oldest accepted version does. Three tests go back to two real nodes, since both ends are their subject: handshake_flags_exchanged and handshake_peering_only_flag check what each node records about the other, and depeer_on_outdated_version checks that the sender's channel dies when the receiver drops the connection. filter_invalid_version_using keeps the receiver's side of that. A comment at the constructor's throw says why a failed connect does not leave the io thread joinable: the delegated constructor has completed, so the destructor runs and joins it.
__________
Type: commit
Hash: 80f037953383fecffd063cf1fa085b9734961c45
Created: today
__________
gr0v1ty/nano-node:80f037953383fecffd063cf1fa085b9734961c45
| Test Case | Status | Duration | Median Deviation | Log | Graph |
|---|---|---|---|---|---|
| No test results available yet. Check the GitHub test run for job status and logs. | |||||