Explorar o código

Move test configs to test_configs crate.

Jing Yang %!s(int64=4) %!d(string=hai) anos
pai
achega
480e04d712

+ 5 - 2
test_configs/Cargo.toml

@@ -4,15 +4,18 @@ version = "0.1.0"
 edition = "2018"
 
 [dependencies]
+anyhow = "1.0"
 async-trait = "0.1"
 bincode = "1.3.3"
+bytes = "1.0"
 labrpc = "0.1.12"
+log = "0.4"
 parking_lot = "0.11.1"
+rand = "0.8"
 ruaft = { path = "..", features = ["integration-test"] }
 serde = "1.0.116"
+test_utils = { path = "../test_utils" }
 
 [dev-dependencies]
-bytes = "1.0"
 futures = { version = "0.3.15", features = ["thread-pool"] }
-test_utils = { path = "../test_utils" }
 stdext = "0.3"

+ 6 - 7
tests/config/mod.rs → test_configs/src/config/mod.rs

@@ -2,16 +2,15 @@ use std::collections::HashMap;
 use std::path::PathBuf;
 use std::rc::Rc;
 use std::sync::Arc;
-use std::time::Instant;
+use std::time::{Duration, Instant};
 
 pub use anyhow::Result;
 use anyhow::{anyhow, bail};
 use parking_lot::Mutex;
 use rand::{thread_rng, Rng};
-use tokio::time::Duration;
 
+use crate::register_server;
 use ruaft::{ApplyCommandMessage, Persister, Raft, Term};
-use test_configs::register_server;
 
 pub mod persister;
 
@@ -304,7 +303,7 @@ impl Config {
         {
             let mut network = self.network.lock();
             for j in 0..self.server_count {
-                clients.push(test_configs::RpcClient::new(network.make_client(
+                clients.push(crate::RpcClient::new(network.make_client(
                     Self::client_name(index, j),
                     Self::server_name(j),
                 )))
@@ -365,7 +364,7 @@ impl Config {
     pub fn end(&self) {}
 
     pub fn cleanup(&self) {
-        log::trace!("Cleaning up test config ...");
+        log::trace!("Cleaning up test raft.config ...");
         let mut network = self.network.lock();
         for i in 0..self.server_count {
             network.remove_server(Self::server_name(i));
@@ -377,7 +376,7 @@ impl Config {
                 raft.kill();
             }
         }
-        log::trace!("Cleaning up test config done.");
+        log::trace!("Cleaning up test raft.config done.");
         eprintln!(
             "Ruaft log file for {}: {:?}",
             self.test_path,
@@ -502,7 +501,7 @@ pub fn make_config(
 }
 
 pub fn sleep_millis(mills: u64) {
-    std::thread::sleep(std::time::Duration::from_millis(mills))
+    std::thread::sleep(Duration::from_millis(mills))
 }
 
 pub const LONG_ELECTION_TIMEOUT_MILLIS: u64 = 1000;

+ 0 - 0
tests/config/persister/mod.rs → test_configs/src/config/persister/mod.rs


+ 1 - 0
test_configs/src/lib.rs

@@ -1,3 +1,4 @@
+pub mod config;
 mod rpcs;
 
 pub use rpcs::{make_rpc_handler, register_server, RpcClient};

+ 1 - 3
tests/agreement_tests.rs

@@ -1,9 +1,7 @@
 #![allow(clippy::identity_op)]
 use rand::{thread_rng, Rng};
 use scopeguard::defer;
-
-// This is to remove the annoying "unused code in config" warnings.
-pub mod config;
+use test_configs::{config, make_config};
 
 #[test]
 fn basic_agreement() -> config::Result<()> {

+ 1 - 3
tests/election_tests.rs

@@ -1,7 +1,5 @@
 use scopeguard::defer;
-
-// This is to remove the annoying "unused code in config" warnings.
-pub mod config;
+use test_configs::{config, make_config};
 
 #[test]
 fn initial_election() -> config::Result<()> {

+ 1 - 3
tests/persist_tests.rs

@@ -6,9 +6,7 @@ use std::sync::Arc;
 
 use rand::{thread_rng, Rng};
 use scopeguard::defer;
-
-// This is to remove the annoying "unused code in config" warnings.
-pub mod config;
+use test_configs::{config, make_config};
 
 #[test]
 fn persist1() -> config::Result<()> {