Skip to content

Commit 3ea2210

Browse files
authored
Improves the robustness of integration tests
We removed the manual assigned port numbers in two integration tests. That ensures that each integration Test uses it's own Redis Server instance We used a separate output directory and filename for the rdb file that may get stored during integration testing.
2 parents 8717c6d + e447ad3 commit 3ea2210

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

tests/integration.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -651,11 +651,7 @@ fn test_open_key_with_flags() -> Result<()> {
651651

652652
#[test]
653653
fn test_expire() -> Result<()> {
654-
let port: u16 = 6502;
655-
let _guards = vec![start_redis_server_with_module("expire", port)
656-
.with_context(|| "failed to start redis server")?];
657-
let mut con =
658-
get_redis_connection(port).with_context(|| "failed to connect to redis server")?;
654+
let mut con = TestConnection::new("expire");
659655

660656
// Create a key without TTL
661657
redis::cmd("set")
@@ -689,11 +685,7 @@ fn test_expire() -> Result<()> {
689685

690686
#[test]
691687
fn test_defrag() -> Result<()> {
692-
let port: u16 = 6503;
693-
let _guards = vec![start_redis_server_with_module("data_type", port)
694-
.with_context(|| "failed to start redis server")?];
695-
let mut con =
696-
get_redis_connection(port).with_context(|| "failed to connect to redis server")?;
688+
let mut con = TestConnection::new("data_type");
697689

698690
// Configure active defrag
699691
redis::cmd("config")

tests/utils.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,34 @@ pub fn start_redis_server_with_module(module_name: &str, port: u16) -> Result<Ch
9595

9696
let module_path = format!("{}", module_path.display());
9797

98+
let rdb_filename = format!("test-on-port-{}.rdb", port);
99+
let rdb_out_dir = std::env::current_dir()?;
100+
let rdb_out_dir = rdb_out_dir.join(format!("target/integration-test/instance-p{}", port));
101+
if rdb_out_dir.exists() {
102+
fs::remove_dir_all(&rdb_out_dir).with_context(|| {
103+
format!(
104+
"Removing existing rdb output dir: {}",
105+
rdb_out_dir.display()
106+
)
107+
})?;
108+
}
109+
110+
fs::create_dir_all(&rdb_out_dir)
111+
.with_context(|| format!("Creating rdb output dir: {}", rdb_out_dir.display()))?;
112+
98113
let args = &[
99114
"--port",
100115
&port.to_string(),
101116
"--loadmodule",
102117
module_path.as_str(),
103118
"--enable-debug-command",
104119
"yes",
120+
"--dir",
121+
rdb_out_dir
122+
.to_str()
123+
.expect("RDB output directory path contains invalid UTF-8 characters"),
124+
"--dbfilename",
125+
rdb_filename.as_str(),
105126
];
106127

107128
let redis_server = Command::new("redis-server")

0 commit comments

Comments
 (0)