Skip to content

Commit b9d2fb9

Browse files
committed
fix: Accidentally nested log directory config
1 parent bdc900d commit b9d2fb9

File tree

6 files changed

+27
-25
lines changed

6 files changed

+27
-25
lines changed

harness/src/raft.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,9 @@ fn run_raft(
7373

7474
let store = HashStore::new();
7575
let logger = build_file_logger(base_storage_path);
76-
let storage_pth = get_storage_path(cfg.get_log_dir(), *node_id);
77-
ensure_directory_exist(storage_pth.as_str())?;
7876

7977
let storage = HeedStorage::create(
80-
&storage_pth,
78+
&cfg.get_log_dir(),
8179
&cfg,
8280
Arc::new(Slogger {
8381
slog: logger.clone(),

harness/src/test_environment.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::{
88
};
99

1010
lazy_static! {
11-
pub static ref COUNTER: AtomicUsize = AtomicUsize::new(1);
11+
static ref IP_COUNTER: AtomicUsize = AtomicUsize::new(1);
1212
}
1313

1414
const COUNTER_FILE: &str = ".ip_counter";
@@ -21,23 +21,26 @@ pub struct TestEnvironment {
2121
pub base_storage_path: String,
2222
}
2323

24-
pub fn get_test_environment(test_name: &str) -> TestEnvironment {
24+
pub fn prepare_test_environment(test_name: &str) -> TestEnvironment {
2525
let test_environment_path = format!("logs/{}", test_name);
2626
let test_environment_path = Path::new(&test_environment_path);
2727

2828
// Remove if the previous test environment exists
2929
if test_environment_path.exists() {
3030
fs::remove_dir_all(test_environment_path)
31-
.expect("Failed to remove previous logs directory");
31+
.expect("Failed to remove previous test environment");
3232
}
3333

3434
// Caution: Storing ip_counter in the tempdir result in different test binaries using duplicate loopback IP addresses,
3535
// so we store the ip_counter file in the harness/logs directory.
36-
get_test_environment_with_counter_file(test_name, COUNTER_FILE)
36+
prepare_test_environment_with_counter_file(test_name, COUNTER_FILE)
3737
}
3838

3939
// Function with adjustable counter file path for testing
40-
fn get_test_environment_with_counter_file(test_name: &str, counter_file: &str) -> TestEnvironment {
40+
fn prepare_test_environment_with_counter_file(
41+
test_name: &str,
42+
counter_file: &str,
43+
) -> TestEnvironment {
4144
let path = Path::new(counter_file);
4245

4346
let mut file = OpenOptions::new()
@@ -123,11 +126,11 @@ mod tests {
123126
write!(file, "{}", MAX_COUNTER - 1).expect("Failed to write to counter file");
124127

125128
// First call: should return last IP address 127.255.255.254
126-
let env = get_test_environment_with_counter_file(test_name, counter_file_str);
129+
let env = prepare_test_environment_with_counter_file(test_name, counter_file_str);
127130
assert_eq!(env.loopback_address, "127.255.255.254");
128131

129132
// Second call: counter wraps around, should return first IP address 127.0.0.1
130-
let env = get_test_environment_with_counter_file(test_name, counter_file_str);
133+
let env = prepare_test_environment_with_counter_file(test_name, counter_file_str);
131134
assert_eq!(env.loopback_address, "127.0.0.1");
132135
}
133136

@@ -140,16 +143,16 @@ mod tests {
140143
let counter_file_str = counter_file_path.to_str().unwrap();
141144

142145
// First allocation
143-
let env = get_test_environment_with_counter_file(test_name, counter_file_str);
146+
let env = prepare_test_environment_with_counter_file(test_name, counter_file_str);
144147
assert_eq!(env.loopback_address, "127.0.0.1");
145148
assert_eq!(env.base_storage_path, "./logs/test_basic");
146149

147150
// Second allocation
148-
let env = get_test_environment_with_counter_file(test_name, counter_file_str);
151+
let env = prepare_test_environment_with_counter_file(test_name, counter_file_str);
149152
assert_eq!(env.loopback_address, "127.0.0.2");
150153

151154
// Third allocation
152-
let env = get_test_environment_with_counter_file(test_name, counter_file_str);
155+
let env = prepare_test_environment_with_counter_file(test_name, counter_file_str);
153156
assert_eq!(env.loopback_address, "127.0.0.3");
154157
}
155158

@@ -167,7 +170,7 @@ mod tests {
167170
write!(file, "{}", counter_value).expect("Failed to write to counter file");
168171

169172
// First call: should return IP address 127.1.1.1
170-
let env = get_test_environment_with_counter_file(test_name, counter_file_str);
173+
let env = prepare_test_environment_with_counter_file(test_name, counter_file_str);
171174
assert_eq!(env.loopback_address, "127.1.1.1");
172175
}
173176

@@ -184,6 +187,6 @@ mod tests {
184187
let counter_file_str = counter_file_path.to_str().unwrap();
185188

186189
// Function call should panic
187-
get_test_environment_with_counter_file(test_name, counter_file_str);
190+
prepare_test_environment_with_counter_file(test_name, counter_file_str);
188191
}
189192
}

harness/src/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ mod tests {
140140

141141
use crate::{
142142
state_machine::{HashStore, LogEntry},
143-
test_environment::get_test_environment,
143+
test_environment::prepare_test_environment,
144144
utils::{gather_rafts_when_leader_elected, load_peers},
145145
};
146146

@@ -153,7 +153,7 @@ mod tests {
153153
use std::sync::mpsc;
154154

155155
let test_environment =
156-
get_test_environment(stringify!(test_gather_rafts_when_leader_elected));
156+
prepare_test_environment(stringify!(test_gather_rafts_when_leader_elected));
157157

158158
let (tx_raft, rx_raft) = mpsc::channel::<(u64, Raft)>();
159159
let peers = load_peers(&test_environment.loopback_address, FIVE_NODE_EXAMPLE)

harness/tests/bootstrap.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use harness::constant::RAFT_PORTS;
22
use std::{process::exit, sync::mpsc, time::Duration};
33
use tokio::time::sleep;
44

5-
use harness::test_environment::get_test_environment;
5+
use harness::test_environment::prepare_test_environment;
66
use harness::{
77
constant::{ONE_NODE_EXAMPLE, THREE_NODE_EXAMPLE},
88
raft::{build_raft_cluster, spawn_and_join_extra_node, wait_until_rafts_ready, Raft},
@@ -11,7 +11,7 @@ use harness::{
1111

1212
#[tokio::test]
1313
pub async fn test_static_bootstrap() {
14-
let test_environment = get_test_environment(stringify!(test_static_bootstrap));
14+
let test_environment = prepare_test_environment(stringify!(test_static_bootstrap));
1515

1616
let (tx_raft, rx_raft) = mpsc::channel::<(u64, Raft)>();
1717

@@ -34,7 +34,8 @@ pub async fn test_static_bootstrap() {
3434

3535
#[tokio::test]
3636
pub async fn test_dynamic_bootstrap() {
37-
let test_environment = get_test_environment(stringify!(test_dynamic_bootstrap));
37+
assert!(false);
38+
let test_environment = prepare_test_environment(stringify!(test_dynamic_bootstrap));
3839

3940
let (tx_raft, rx_raft) = mpsc::channel::<(u64, Raft)>();
4041

harness/tests/data_replication.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ use harness::{
66
constant::{RAFT_PORTS, THREE_NODE_EXAMPLE},
77
raft::{build_raft_cluster, spawn_and_join_extra_node, wait_until_rafts_ready, Raft},
88
state_machine::LogEntry,
9-
test_environment::get_test_environment,
9+
test_environment::prepare_test_environment,
1010
utils::load_peers,
1111
};
1212

1313
#[tokio::test]
1414
pub async fn test_data_replication() {
15-
let test_environment = get_test_environment(stringify!(test_data_replication));
15+
let test_environment = prepare_test_environment(stringify!(test_data_replication));
1616

1717
let peers = load_peers(&test_environment.loopback_address, THREE_NODE_EXAMPLE)
1818
.await

harness/tests/leader_election.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{process::exit, sync::mpsc};
44
use harness::{
55
constant::{FIVE_NODE_EXAMPLE, THREE_NODE_EXAMPLE},
66
raft::{build_raft_cluster, wait_until_rafts_ready, Raft},
7-
test_environment::{get_test_environment, TestEnvironment},
7+
test_environment::{prepare_test_environment, TestEnvironment},
88
utils::{gather_rafts_when_leader_elected, load_peers},
99
};
1010

@@ -94,7 +94,7 @@ async fn run_leader_election_test(
9494
#[tokio::test]
9595
pub async fn test_leader_election_in_five_node_cluster() {
9696
run_leader_election_test(
97-
get_test_environment(stringify!(test_leader_election_in_five_node_cluster)),
97+
prepare_test_environment(stringify!(test_leader_election_in_five_node_cluster)),
9898
FIVE_NODE_EXAMPLE,
9999
2,
100100
)
@@ -104,7 +104,7 @@ pub async fn test_leader_election_in_five_node_cluster() {
104104
#[tokio::test]
105105
pub async fn test_leader_election_in_three_node_cluster() {
106106
run_leader_election_test(
107-
get_test_environment(stringify!(test_leader_election_in_three_node_cluster)),
107+
prepare_test_environment(stringify!(test_leader_election_in_three_node_cluster)),
108108
THREE_NODE_EXAMPLE,
109109
1,
110110
)

0 commit comments

Comments
 (0)