@@ -124,19 +124,15 @@ impl RedisCluster {
124
124
num_replicas : replicas,
125
125
modules,
126
126
mtls_enabled,
127
- mut ports,
127
+ ports,
128
128
} = configuration;
129
129
130
- if ports. is_empty ( ) {
131
- // We use a hashset in order to be sure that we have the right number
132
- // of unique ports.
133
- let mut hash = std:: collections:: HashSet :: new ( ) ;
134
- while hash. len ( ) < nodes as usize {
135
- hash. insert ( get_random_available_port ( ) ) ;
136
- }
137
- ports = hash. into_iter ( ) . collect ( ) ;
138
- }
139
- println ! ( "Chosen ports: {ports:?}" ) ;
130
+ let port_options = if ports. is_empty ( ) {
131
+ vec ! [ None ; nodes as usize ]
132
+ } else {
133
+ println ! ( "Chosen ports: {ports:?}" ) ;
134
+ ports. into_iter ( ) . map ( Some ) . collect ( )
135
+ } ;
140
136
141
137
let mut servers = vec ! [ ] ;
142
138
let mut folders = vec ! [ ] ;
@@ -159,7 +155,8 @@ impl RedisCluster {
159
155
160
156
let max_attempts = 5 ;
161
157
162
- for port in ports {
158
+ for port_option in port_options {
159
+ let port = port_option. unwrap_or_else ( get_random_available_port) ;
163
160
servers. push ( RedisServer :: new_with_addr_tls_modules_and_spawner (
164
161
ClusterType :: build_addr ( port) ,
165
162
None ,
@@ -199,7 +196,7 @@ impl RedisCluster {
199
196
folders. push ( tempdir) ;
200
197
addrs. push ( addr. clone ( ) ) ;
201
198
202
- cmd. spawn ( ) . unwrap ( )
199
+ cmd. spawn ( ) . unwrap ( )
203
200
} ,
204
201
) ) ;
205
202
}
@@ -209,9 +206,11 @@ impl RedisCluster {
209
206
for server in servers. iter_mut ( ) {
210
207
let process = & mut server. process ;
211
208
match process. try_wait ( ) {
212
- Ok ( Some ( status) ) => {
213
- let contents = std:: fs:: read_to_string ( server. log_file . clone ( ) ) . unwrap ( ) ;
214
- panic ! ( "redis server creation failed with status {status:?}.\n logfile: {contents}" ) ;
209
+ Ok ( Some ( status) ) => {
210
+ let contents = std:: fs:: read_to_string ( server. log_file . clone ( ) ) . unwrap ( ) ;
211
+ panic ! (
212
+ "redis server creation failed with status {status:?}.\n logfile: {contents}"
213
+ ) ;
215
214
}
216
215
Ok ( None ) => {
217
216
// wait for 10 seconds for the server to be available.
0 commit comments