Skip to content

Commit

Permalink
Use free ports for cluster tests.
Browse files Browse the repository at this point in the history
This ensures that the cluster tests won't compete with each other for the same ports.
  • Loading branch information
nihohit authored and barshaul committed Jun 26, 2024
1 parent 5e8e532 commit 2088795
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion redis/tests/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ impl TestContext {
let millisecond = Duration::from_millis(1);
let mut retries = 0;
loop {
match client.get_connection() {
match client.get_connection(None) {
Err(err) => {
if err.is_connection_refusal() {
sleep(millisecond);
Expand Down
11 changes: 7 additions & 4 deletions redis/tests/test_cluster_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3514,10 +3514,13 @@ mod cluster_async {
drop(cluster);

// recreate cluster
let _cluster = RedisCluster::new(RedisClusterConfiguration {
ports: ports.clone(),
..Default::default()
});
let _cluster = TestClusterContext::new_with_config_and_builder(
RedisClusterConfiguration {
ports: ports.clone(),
..Default::default()
},
|builder| builder.retries(2),
);

let cmd = cmd("PING");
// explicitly route to all primaries and request all succeeded
Expand Down
30 changes: 18 additions & 12 deletions redis/tests/test_cluster_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ mod test_cluster_scan_async {

#[tokio::test]
async fn test_async_cluster_scan() {
let cluster = TestClusterContext::new(3, 0);
let cluster = TestClusterContext::new();
let mut connection = cluster.async_connection(None).await;

// Set some keys
Expand Down Expand Up @@ -88,7 +88,7 @@ mod test_cluster_scan_async {

#[tokio::test] // test cluster scan with slot migration in the middle
async fn test_async_cluster_scan_with_migration() {
let cluster = TestClusterContext::new(3, 0);
let cluster = TestClusterContext::new();

let mut connection = cluster.async_connection(None).await;
// Set some keys
Expand Down Expand Up @@ -163,7 +163,7 @@ mod test_cluster_scan_async {

#[tokio::test] // test cluster scan with node fail in the middle
async fn test_async_cluster_scan_with_fail() {
let cluster = TestClusterContext::new(3, 0);
let cluster = TestClusterContext::new();
let mut connection = cluster.async_connection(None).await;
// Set some keys
for i in 0..1000 {
Expand Down Expand Up @@ -227,8 +227,11 @@ mod test_cluster_scan_async {

#[tokio::test] // Test cluster scan with killing all masters during scan
async fn test_async_cluster_scan_with_all_masters_down() {
let cluster = TestClusterContext::new(6, 1);

let cluster = TestClusterContext::new_with_config(RedisClusterConfiguration {
nodes: 6,
replicas: 1,
..Default::default()
});
let mut connection = cluster.async_connection(None).await;

let mut expected_keys: Vec<String> = Vec::new();
Expand Down Expand Up @@ -373,8 +376,11 @@ mod test_cluster_scan_async {
#[tokio::test]
// Test cluster scan with killing all replicas during scan
async fn test_async_cluster_scan_with_all_replicas_down() {
let cluster = TestClusterContext::new(6, 1);

let cluster = TestClusterContext::new_with_config(RedisClusterConfiguration {
nodes: 6,
replicas: 1,
..Default::default()
});
let mut connection = cluster.async_connection(None).await;

let mut expected_keys: Vec<String> = Vec::new();
Expand Down Expand Up @@ -469,7 +475,7 @@ mod test_cluster_scan_async {
#[tokio::test]
// Test cluster scan with setting keys for each iteration
async fn test_async_cluster_scan_set_in_the_middle() {
let cluster = TestClusterContext::new(3, 0);
let cluster = TestClusterContext::new();
let mut connection = cluster.async_connection(None).await;
let mut expected_keys: Vec<String> = Vec::new();
let mut i = 0;
Expand Down Expand Up @@ -528,7 +534,7 @@ mod test_cluster_scan_async {
#[tokio::test]
// Test cluster scan with deleting keys for each iteration
async fn test_async_cluster_scan_dell_in_the_middle() {
let cluster = TestClusterContext::new(3, 0);
let cluster = TestClusterContext::new();

let mut connection = cluster.async_connection(None).await;
let mut expected_keys: Vec<String> = Vec::new();
Expand Down Expand Up @@ -590,7 +596,7 @@ mod test_cluster_scan_async {
#[tokio::test]
// Testing cluster scan with Pattern option
async fn test_async_cluster_scan_with_pattern() {
let cluster = TestClusterContext::new(3, 0);
let cluster = TestClusterContext::new();
let mut connection = cluster.async_connection(None).await;
let mut expected_keys: Vec<String> = Vec::new();
let mut i = 0;
Expand Down Expand Up @@ -648,7 +654,7 @@ mod test_cluster_scan_async {
#[tokio::test]
// Testing cluster scan with TYPE option
async fn test_async_cluster_scan_with_type() {
let cluster = TestClusterContext::new(3, 0);
let cluster = TestClusterContext::new();
let mut connection = cluster.async_connection(None).await;
let mut expected_keys: Vec<String> = Vec::new();
let mut i = 0;
Expand Down Expand Up @@ -706,7 +712,7 @@ mod test_cluster_scan_async {
#[tokio::test]
// Testing cluster scan with COUNT option
async fn test_async_cluster_scan_with_count() {
let cluster = TestClusterContext::new(3, 0);
let cluster = TestClusterContext::new();
let mut connection = cluster.async_connection(None).await;
let mut expected_keys: Vec<String> = Vec::new();
let mut i = 0;
Expand Down

0 comments on commit 2088795

Please sign in to comment.