Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
AureliaDolo committed Mar 1, 2022
1 parent 93ec2ff commit bfe346e
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 26 deletions.
4 changes: 4 additions & 0 deletions massa-network-exports/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ massa_time = { path = "../massa-time" }
serde_json = "1.0"
tempfile = "3.2"

[dev-dependencies]
massa_models = { path = "../massa-models", features = ["testing"] }

[features]
instrument = [ "massa_models/instrument", "massa_time/instrument"]
testing = ["massa_models/testing"]
40 changes: 20 additions & 20 deletions massa-network-exports/src/establisher.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
// Copyright (c) 2022 MASSA LABS <[email protected]>

#[cfg(not(test))]
#[cfg(not(feature = "testing"))]
use massa_time::MassaTime;
#[cfg(not(test))]
#[cfg(not(feature = "testing"))]
use std::{io, net::SocketAddr};
#[cfg(not(test))]
#[cfg(not(feature = "testing"))]
use tokio::{
net::{TcpListener, TcpStream},
time::timeout,
};

#[cfg(test)]
#[cfg(feature = "testing")]
pub type ReadHalf = super::test_exports::mock_establisher::ReadHalf;
#[cfg(test)]
#[cfg(feature = "testing")]
pub type WriteHalf = super::test_exports::mock_establisher::WriteHalf;
#[cfg(test)]
#[cfg(feature = "testing")]
pub type Listener = super::test_exports::mock_establisher::MockListener;
#[cfg(test)]
#[cfg(feature = "testing")]
pub type Connector = super::test_exports::mock_establisher::MockConnector;
#[cfg(test)]
#[cfg(feature = "testing")]
pub type Establisher = super::test_exports::mock_establisher::MockEstablisher;

#[cfg(not(test))]
#[cfg(not(feature = "testing"))]
pub type ReadHalf = tokio::net::tcp::OwnedReadHalf;
#[cfg(not(test))]
#[cfg(not(feature = "testing"))]
pub type WriteHalf = tokio::net::tcp::OwnedWriteHalf;
#[cfg(not(test))]
#[cfg(not(feature = "testing"))]
pub type Listener = DefaultListener;
#[cfg(not(test))]
#[cfg(not(feature = "testing"))]
pub type Connector = DefaultConnector;
#[cfg(not(test))]
#[cfg(not(feature = "testing"))]
pub type Establisher = DefaultEstablisher;

/// The listener we are using
#[cfg(not(test))]
#[cfg(not(feature = "testing"))]
#[derive(Debug)]
pub struct DefaultListener(TcpListener);

#[cfg(not(test))]
#[cfg(not(feature = "testing"))]
impl DefaultListener {
/// Accepts a new incoming connection from this listener.
pub async fn accept(&mut self) -> io::Result<(ReadHalf, WriteHalf, SocketAddr)> {
Expand All @@ -48,11 +48,11 @@ impl DefaultListener {
}

/// Initiates a connection with given timeout in millis
#[cfg(not(test))]
#[cfg(not(feature = "testing"))]
#[derive(Debug)]
pub struct DefaultConnector(MassaTime);

#[cfg(not(test))]
#[cfg(not(feature = "testing"))]
impl DefaultConnector {
/// Tries to connect to addr
///
Expand All @@ -71,11 +71,11 @@ impl DefaultConnector {
}

/// Establishes a connection
#[cfg(not(test))]
#[cfg(not(feature = "testing"))]
#[derive(Debug)]
pub struct DefaultEstablisher;

#[cfg(not(test))]
#[cfg(not(feature = "testing"))]
impl DefaultEstablisher {
/// Creates an Establisher.
pub fn new() -> Self {
Expand All @@ -102,7 +102,7 @@ impl DefaultEstablisher {
}
}

#[cfg(not(test))]
#[cfg(not(feature = "testing"))]
impl Default for DefaultEstablisher {
fn default() -> Self {
Self::new()
Expand Down
5 changes: 1 addition & 4 deletions massa-network-exports/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,5 @@ mod network_controller;
mod peers;
pub mod settings;

#[cfg(test)]
#[cfg(feature = "testing")]
pub mod test_exports;

#[cfg(test)]
pub use settings::tests;
2 changes: 1 addition & 1 deletion massa-network-exports/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub struct NetworkSettings {
pub max_in_connection_overflow: usize,
}

#[cfg(test)]
#[cfg(feature = "testing")]
pub mod tests {
use crate::{test_exports::tools::get_temp_private_key_file, NetworkSettings};
use massa_models::constants::BASE_NETWORK_CONTROLLER_IP;
Expand Down
3 changes: 3 additions & 0 deletions massa-network-exports/src/test_exports/mock_establisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ pub struct MockEstablisher {
}

impl MockEstablisher {
pub fn new() -> Self {
unreachable!("place holder")
}
pub async fn get_listener(&mut self, _addr: SocketAddr) -> io::Result<MockListener> {
Ok(MockListener {
connection_listener_rx: self
Expand Down
1 change: 1 addition & 0 deletions massa-network-worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pretty_assertions = "1.0"
serial_test = "0.5.1"
tempfile = "3.2"
massa_models = { path = "../massa-models", features = ["testing"] }
massa_network_exports = { path = "../massa-network-exports", features = ["testing"] }

[features]
instrument = ["tokio/tracing", "massa_models/instrument", "massa_time/instrument", "massa_network_exports/instrument"]
2 changes: 1 addition & 1 deletion massa-network-worker/src/tests/test_peer_info_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod tests {

use super::*;
use massa_network_exports::{
tests, NetworkConnectionErrorType, NetworkError, NetworkSettings, PeerInfo,
NetworkConnectionErrorType, NetworkError, NetworkSettings, PeerInfo,
};
use serial_test::serial;
use tokio::sync::watch;
Expand Down

0 comments on commit bfe346e

Please sign in to comment.