104 lines
3.6 KiB
Rust
104 lines
3.6 KiB
Rust
use std::sync::Arc;
|
|
use std::time::Duration;
|
|
|
|
use rcom::app::{Command, PaneId, PaneMode};
|
|
use rcom::domain::{HostAlias, Location, SourceId};
|
|
use rcom::fs::{BackendRegistry, LocalFs};
|
|
use rcom::session::Application;
|
|
use rcom::ssh::{ConnectionManager, DiscoveryResult, OpenSshConnector};
|
|
use tokio::sync::mpsc;
|
|
|
|
async fn settle(application: &mut Application, results: &mut mpsc::Receiver<Command>) {
|
|
loop {
|
|
match tokio::time::timeout(Duration::from_secs(2), results.recv()).await {
|
|
Ok(Some(command)) => application.dispatch(command),
|
|
Ok(None) => panic!("result channel closed"),
|
|
Err(_) => break,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[tokio::test]
|
|
#[ignore = "read-only acceptance on the explicitly authorized hermesVM host"]
|
|
async fn hermesvm_local_ssh_dual_and_reconnect_are_read_only() {
|
|
let host = HostAlias::new(
|
|
std::env::var("RCOM_TEST_SSH_HOST").unwrap_or_else(|_| "hermesVM".to_owned()),
|
|
);
|
|
let registry = BackendRegistry::new(Arc::new(LocalFs::new()));
|
|
let connections = ConnectionManager::new(Arc::new(OpenSshConnector::default()), registry);
|
|
let manager = connections.clone();
|
|
let (mut application, mut results) = Application::new(
|
|
Location::local("/"),
|
|
connections,
|
|
DiscoveryResult {
|
|
hosts: vec![host.to_string()],
|
|
warnings: Vec::new(),
|
|
},
|
|
);
|
|
|
|
application.start();
|
|
settle(&mut application, &mut results).await;
|
|
application.dispatch(Command::TogglePaneMode);
|
|
application.dispatch(Command::ConnectSsh(host.clone()));
|
|
settle(&mut application, &mut results).await;
|
|
|
|
let left = application.state().pane(PaneId::Left);
|
|
let right = application.state().pane(PaneId::Right);
|
|
assert_eq!(application.state().mode, PaneMode::Dual);
|
|
assert_eq!(left.location.source, SourceId::Ssh(host.clone()));
|
|
assert!(left.location.path().is_absolute());
|
|
assert_eq!(right.location.source, SourceId::Local);
|
|
assert!(
|
|
left.error.is_none(),
|
|
"remote listing failed: {:?}",
|
|
left.error
|
|
);
|
|
assert!(
|
|
right.error.is_none(),
|
|
"local listing failed: {:?}",
|
|
right.error
|
|
);
|
|
assert!(left.preview.error.is_none(), "remote preview failed");
|
|
assert!(left.preview.content.is_some(), "remote preview is missing");
|
|
assert!(
|
|
left.entries
|
|
.iter()
|
|
.all(|entry| entry.name != "." && entry.name != "..")
|
|
);
|
|
|
|
let first = manager
|
|
.current(&host)
|
|
.await
|
|
.expect("connection must be cached");
|
|
let bounded = first.backend().list_prefix(&first.home, 101).await.unwrap();
|
|
assert!(bounded.len() <= 101);
|
|
let second = manager.connect(&host).await.unwrap();
|
|
assert_eq!(first.epoch, second.epoch, "live connection must be reused");
|
|
|
|
manager.invalidate_if_epoch(&host, first.epoch).await;
|
|
application.dispatch(Command::ConnectSsh(host.clone()));
|
|
settle(&mut application, &mut results).await;
|
|
let reconnected = manager
|
|
.current(&host)
|
|
.await
|
|
.expect("reconnect must succeed");
|
|
assert!(reconnected.epoch > first.epoch);
|
|
assert!(application.state().pane(PaneId::Left).error.is_none());
|
|
|
|
// A late error from the previous epoch must not remove the replacement connection.
|
|
manager.invalidate_if_epoch(&host, first.epoch).await;
|
|
assert_eq!(
|
|
manager.current(&host).await.unwrap().epoch,
|
|
reconnected.epoch
|
|
);
|
|
assert!(
|
|
manager
|
|
.resolve(&reconnected.home, Some(reconnected.epoch))
|
|
.await
|
|
.is_ok()
|
|
);
|
|
assert_eq!(
|
|
application.state().pane(PaneId::Right).location.source,
|
|
SourceId::Local
|
|
);
|
|
}
|