Browse Source

Make the "integration-test" dependency optional in kvraft.

Jing Yang 3 years ago
parent
commit
b2ed8dfad9
4 changed files with 17 additions and 6 deletions
  1. 1 1
      durio/Cargo.toml
  2. 5 2
      kvraft/Cargo.toml
  3. 10 2
      kvraft/src/server.rs
  4. 1 1
      test_configs/Cargo.toml

+ 1 - 1
durio/Cargo.toml

@@ -22,7 +22,7 @@ kvraft = { path = "../kvraft" }
 lazy_static = "1.4.0"
 log = "0.4"
 parking_lot = "0.12"
-ruaft = { path = "..", features = ["integration-test"] }
+ruaft = { path = ".." }
 serde = "1.0"
 serde_derive = "1.0"
 serde_json = "1.0"

+ 5 - 2
kvraft/Cargo.toml

@@ -10,13 +10,16 @@ futures = "0.3.21"
 log = "0.4"
 parking_lot = "0.12"
 rand = "0.8"
-ruaft = { path = "..", features = ["integration-test"] }
+ruaft = { path = ".." }
 serde = "1.0"
 serde_derive = "1.0"
-test_utils = { path = "../test_utils" }
+test_utils = { path = "../test_utils", optional = true }
 tokio = { version = "1.7", features = ["time", "parking_lot"] }
 
 [dev-dependencies]
 scopeguard = "1.1.0"
 stdext = "0.3"
 test_configs = { path = "../test_configs" }
+
+[features]
+integration-test = ["test_utils"]

+ 10 - 2
kvraft/src/server.rs

@@ -13,8 +13,8 @@ use ruaft::{
     ApplyCommandMessage, Index, Persister, Raft, RemoteRaft, Term,
     VerifyAuthorityResult,
 };
-use test_utils::log_with;
-use test_utils::thread_local_logger::LocalLogger;
+#[cfg(all(not(test), feature = "integration-test"))]
+use test_utils::{log_with, thread_local_logger::LocalLogger};
 
 use crate::common::{
     ClerkId, CommitSentinelArgs, CommitSentinelReply, GetArgs, GetReply,
@@ -27,6 +27,7 @@ pub struct KVServer {
     state: Mutex<KVServerState>,
     rf: Raft<UniqueKVOp>,
     keep_running: AtomicBool,
+    #[cfg(all(not(test), feature = "integration-test"))]
     logger: LocalLogger,
 }
 
@@ -134,6 +135,7 @@ impl KVServer {
                 move |index| snapshot_holder_clone.request_snapshot(index),
             ),
             keep_running: AtomicBool::new(true),
+            #[cfg(all(not(test), feature = "integration-test"))]
             logger: LocalLogger::inherit(),
         });
         ret.process_command(snapshot_holder, rx);
@@ -230,9 +232,11 @@ impl KVServer {
         command_channel: Receiver<ApplyCommandMessage<UniqueKVOp>>,
     ) {
         let this = Arc::downgrade(self);
+        #[cfg(all(not(test), feature = "integration-test"))]
         let logger = LocalLogger::inherit();
         let me = self.me;
         std::thread::spawn(move || {
+            #[cfg(all(not(test), feature = "integration-test"))]
             logger.attach();
             log::info!("KVServer {} waiting for commands ...", me);
             while let Ok(message) = command_channel.recv() {
@@ -380,7 +384,11 @@ impl KVServer {
                 me: self.me,
                 unique_id,
             };
+            #[cfg(all(not(test), feature = "integration-test"))]
             let start = log_with!(self.logger, self.rf.start(op));
+            #[cfg(not(all(not(test), feature = "integration-test")))]
+            let start = self.rf.start(op);
+
             let start_term = start.map_or(Self::UNSEEN_TERM, |index_term| {
                 let Term(term) = index_term.term;
                 Self::validate_term(term);

+ 1 - 1
test_configs/Cargo.toml

@@ -9,7 +9,7 @@ async-trait = "0.1"
 bincode = "1.3.3"
 bytes = "1.1"
 futures-util = "0.3.21"
-kvraft = { path = "../kvraft" }
+kvraft = { path = "../kvraft", features = ["integration-test"] }
 labrpc = "0.2.2"
 linearizability = { path = "../linearizability" }
 log = "0.4"