♻️ refactor: end_to_end test now uses TestingRelay and TestingServer
parent
8b845b55da
commit
4838a99288
81
src/tests.rs
81
src/tests.rs
|
@ -141,8 +141,6 @@ impl TestingServer {
|
|||
|
||||
#[test]
|
||||
fn end_to_end () {
|
||||
use ptth_relay::key_validity::BlakeHashWrapper;
|
||||
|
||||
// Prefer this form for tests, since all tests share one process
|
||||
// and we don't care if another test already installed a subscriber.
|
||||
|
||||
|
@ -151,59 +149,25 @@ fn end_to_end () {
|
|||
|
||||
// Spawn the root task
|
||||
rt.block_on (async {
|
||||
let relay_port = 4000;
|
||||
// No proxy
|
||||
let proxy_port = relay_port;
|
||||
let server_name = "aliens_wildland";
|
||||
let api_key = "AnacondaHardcoverGrannyUnlatchLankinessMutate";
|
||||
let tripcode = BlakeHashWrapper::from_key (api_key.as_bytes ());
|
||||
debug! ("Relay is expecting tripcode {}", tripcode.encode_base64 ());
|
||||
let config_file = ptth_relay::config::file::Config {
|
||||
iso: Default::default (),
|
||||
port: None,
|
||||
servers: vec! [
|
||||
ptth_relay::config::file::Server {
|
||||
name: server_name.to_string (),
|
||||
tripcode,
|
||||
display_name: None,
|
||||
},
|
||||
],
|
||||
scraper_keys: vec! [],
|
||||
|
||||
let testing_config = TestingConfig {
|
||||
server_name,
|
||||
api_key: "AnacondaHardcoverGrannyUnlatchLankinessMutate",
|
||||
|
||||
proxy_port,
|
||||
relay_port,
|
||||
};
|
||||
let relay_url = testing_config.relay_url ();
|
||||
|
||||
let config = ptth_relay::config::Config::try_from (config_file).expect ("Can't load config");
|
||||
let testing_relay = TestingRelay::new (&testing_config).await;
|
||||
let testing_server = TestingServer::new (&testing_config).await;
|
||||
wait_for_any_server (&testing_relay.state).await;
|
||||
|
||||
let relay_state = Arc::new (ptth_relay::RelayState::try_from (config).expect ("Can't create relay state"));
|
||||
|
||||
let relay_state_2 = relay_state.clone ();
|
||||
let (stop_relay_tx, stop_relay_rx) = oneshot::channel ();
|
||||
let task_relay = spawn (async move {
|
||||
ptth_relay::run_relay (
|
||||
relay_state_2,
|
||||
Arc::new (load_templates (&PathBuf::new ())?),
|
||||
stop_relay_rx,
|
||||
None
|
||||
).await
|
||||
});
|
||||
|
||||
assert! (relay_state.list_servers ().await.is_empty ());
|
||||
|
||||
let relay_url = "http://127.0.0.1:4000";
|
||||
|
||||
let config_file = ptth_server::ConfigFile {
|
||||
name: server_name.into (),
|
||||
api_key: api_key.into (),
|
||||
relay_url: "http://127.0.0.1:4000/7ZSFUKGV".into (),
|
||||
file_server_root: None,
|
||||
};
|
||||
|
||||
let (stop_server_tx, stop_server_rx) = oneshot::channel ();
|
||||
let task_server = {
|
||||
spawn (async move {
|
||||
ptth_server::run_server (config_file, stop_server_rx, None, None).await
|
||||
})
|
||||
};
|
||||
|
||||
delay_for (Duration::from_millis (1000)).await;
|
||||
|
||||
assert_eq! (relay_state.list_servers ().await, vec! [
|
||||
assert_eq! (testing_relay.state.list_servers ().await, vec! [
|
||||
server_name.to_string (),
|
||||
]);
|
||||
|
||||
|
@ -243,16 +207,8 @@ fn end_to_end () {
|
|||
|
||||
info! ("Shutting down end-to-end test");
|
||||
|
||||
stop_server_tx.send (()).expect ("Couldn't shut down server");
|
||||
stop_relay_tx.send (()).expect ("Couldn't shut down relay");
|
||||
|
||||
info! ("Sent stop messages");
|
||||
|
||||
task_relay.await.expect ("Couldn't join relay").expect ("Relay error");
|
||||
info! ("Relay stopped");
|
||||
|
||||
task_server.await.expect ("Couldn't join server").expect ("Server error");
|
||||
info! ("Server stopped");
|
||||
testing_server.graceful_shutdown ().await;
|
||||
testing_relay.graceful_shutdown ().await;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -268,11 +224,10 @@ fn debug_proxy () {
|
|||
// Start relay
|
||||
|
||||
let server_name = "aliens_wildland";
|
||||
let api_key = "AnacondaHardcoverGrannyUnlatchLankinessMutate";
|
||||
|
||||
let testing_config = TestingConfig {
|
||||
server_name,
|
||||
api_key,
|
||||
api_key: "AnacondaHardcoverGrannyUnlatchLankinessMutate",
|
||||
|
||||
proxy_port,
|
||||
relay_port,
|
||||
|
|
Loading…
Reference in New Issue