Skip to content

Commit 4fd117d

Browse files
committed
integration: Use let while
Signed-off-by: Akira Moroo <[email protected]>
1 parent 9c09634 commit 4fd117d

File tree

1 file changed

+27
-31
lines changed

1 file changed

+27
-31
lines changed

src/integration.rs

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -412,37 +412,33 @@ mod tests {
412412
let mut s = String::new();
413413

414414
let mut counter = 0;
415-
loop {
416-
if let Err(e) = (|| -> Result<(), SSHCommandError> {
417-
let tcp =
418-
TcpStream::connect(format!("{ip}:22")).map_err(SSHCommandError::Connection)?;
419-
let mut sess = ssh2::Session::new().unwrap();
420-
sess.set_tcp_stream(tcp);
421-
sess.handshake().map_err(SSHCommandError::Handshake)?;
422-
423-
sess.userauth_password(&auth.username, &auth.password)
424-
.map_err(SSHCommandError::Authentication)?;
425-
assert!(sess.authenticated());
426-
427-
let mut channel = sess
428-
.channel_session()
429-
.map_err(SSHCommandError::ChannelSession)?;
430-
channel.exec(command).map_err(SSHCommandError::Command)?;
431-
432-
// Intentionally ignore these results here as their failure
433-
// does not precipitate a repeat
434-
let _ = channel.read_to_string(&mut s);
435-
let _ = channel.close();
436-
let _ = channel.wait_close();
437-
Ok(())
438-
})() {
439-
counter += 1;
440-
if counter >= retries {
441-
return Err(e);
442-
}
443-
} else {
444-
break;
445-
};
415+
while let Err(e) = (|| -> Result<(), SSHCommandError> {
416+
let tcp =
417+
TcpStream::connect(format!("{ip}:22")).map_err(SSHCommandError::Connection)?;
418+
let mut sess = ssh2::Session::new().unwrap();
419+
sess.set_tcp_stream(tcp);
420+
sess.handshake().map_err(SSHCommandError::Handshake)?;
421+
422+
sess.userauth_password(&auth.username, &auth.password)
423+
.map_err(SSHCommandError::Authentication)?;
424+
assert!(sess.authenticated());
425+
426+
let mut channel = sess
427+
.channel_session()
428+
.map_err(SSHCommandError::ChannelSession)?;
429+
channel.exec(command).map_err(SSHCommandError::Command)?;
430+
431+
// Intentionally ignore these results here as their failure
432+
// does not precipitate a repeat
433+
let _ = channel.read_to_string(&mut s);
434+
let _ = channel.close();
435+
let _ = channel.wait_close();
436+
Ok(())
437+
})() {
438+
counter += 1;
439+
if counter >= retries {
440+
return Err(e);
441+
}
446442
thread::sleep(std::time::Duration::new((timeout * counter).into(), 0));
447443
}
448444
Ok(s)

0 commit comments

Comments
 (0)