Tests for nodes/listeners.rs (#541)

* Add unit tests for core::nodes::NodeStream

* Move DummyMuxer to core/tests

* Address grumbles

* Impl Debug for SubstreamRef<P>

* Add test for poll()

* Don't need to open a substream

* pretty printer test

* More tests for NodeStream poll()

* ListenerStream unit tests: transport() and listeners()

* Tests for nodes/listeners.rs

* Add a few tests to help illustrate the "drowning" behaviour of busy listeners

* Address grumbles

* Remove non-project specific stuff

* Address grumbles

* Prefer freestanding function
This commit is contained in:
David
2018-10-10 16:27:07 +02:00
committed by Pierre Krieger
parent dec7cd13b2
commit 0c7f313146
5 changed files with 295 additions and 10 deletions

View File

@ -45,21 +45,21 @@ pub trait NodeHandler<TSubstream> {
/// The handler is responsible for upgrading the substream to whatever protocol it wants.
fn inject_substream(&mut self, substream: TSubstream, endpoint: NodeHandlerEndpoint<Self::OutboundOpenInfo>);
/// Indicates the handler that the inbound part of the muxer has been closed, and that
/// Indicates to the handler that the inbound part of the muxer has been closed, and that
/// therefore no more inbound substream will be produced.
fn inject_inbound_closed(&mut self);
/// Indicates the handler that an outbound substream failed to open because the outbound
/// Indicates to the handler that an outbound substream failed to open because the outbound
/// part of the muxer has been closed.
fn inject_outbound_closed(&mut self, user_data: Self::OutboundOpenInfo);
/// Indicates the handler that the multiaddr future has resolved.
/// Indicates to the handler that the multiaddr future has resolved.
fn inject_multiaddr(&mut self, multiaddr: Result<Multiaddr, IoError>);
/// Injects an event coming from the outside in the handler.
/// Injects an event coming from the outside into the handler.
fn inject_event(&mut self, event: Self::InEvent);
/// Indicates the node that it should shut down. After that, it is expected that `poll()`
/// Indicates that the node that it should shut down. After that, it is expected that `poll()`
/// returns `Ready(None)` as soon as possible.
///
/// This method allows an implementation to perform a graceful shutdown of the substreams, and
@ -78,7 +78,7 @@ pub enum NodeHandlerEndpoint<TOutboundOpenInfo> {
Listener,
}
/// Event produces by a handler.
/// Event produced by a handler.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum NodeHandlerEvent<TOutboundOpenInfo, TCustom> {
/// Require a new outbound substream to be opened with the remote.
@ -88,7 +88,7 @@ pub enum NodeHandlerEvent<TOutboundOpenInfo, TCustom> {
Custom(TCustom),
}
/// Event produces by a handler.
/// Event produced by a handler.
impl<TOutboundOpenInfo, TCustom> NodeHandlerEvent<TOutboundOpenInfo, TCustom> {
/// If this is `OutboundSubstreamRequest`, maps the content to something else.
#[inline]
@ -173,7 +173,7 @@ where
self.node.is_none()
}
/// Indicates the handled node that it should shut down. After calling this method, the
/// Indicates to the handled node that it should shut down. After calling this method, the
/// `Stream` will end in the not-so-distant future.
///
/// After this method returns, `is_shutting_down()` should return true.