♻️ refactor: end_to_end test now uses TestingRelay and TestingServer

main
_ 2021-03-06 19:30:05 +00:00
parent 8b845b55da
commit 4838a99288
1 changed files with 18 additions and 63 deletions

View File

@ -141,8 +141,6 @@ impl TestingServer {
#[test] #[test]
fn end_to_end () { fn end_to_end () {
use ptth_relay::key_validity::BlakeHashWrapper;
// Prefer this form for tests, since all tests share one process // Prefer this form for tests, since all tests share one process
// and we don't care if another test already installed a subscriber. // and we don't care if another test already installed a subscriber.
@ -151,59 +149,25 @@ fn end_to_end () {
// Spawn the root task // Spawn the root task
rt.block_on (async { rt.block_on (async {
let relay_port = 4000;
// No proxy
let proxy_port = relay_port;
let server_name = "aliens_wildland"; let server_name = "aliens_wildland";
let api_key = "AnacondaHardcoverGrannyUnlatchLankinessMutate";
let tripcode = BlakeHashWrapper::from_key (api_key.as_bytes ()); let testing_config = TestingConfig {
debug! ("Relay is expecting tripcode {}", tripcode.encode_base64 ()); server_name,
let config_file = ptth_relay::config::file::Config { api_key: "AnacondaHardcoverGrannyUnlatchLankinessMutate",
iso: Default::default (),
port: None, proxy_port,
servers: vec! [ relay_port,
ptth_relay::config::file::Server {
name: server_name.to_string (),
tripcode,
display_name: None,
},
],
scraper_keys: vec! [],
}; };
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")); assert_eq! (testing_relay.state.list_servers ().await, vec! [
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! [
server_name.to_string (), server_name.to_string (),
]); ]);
@ -243,16 +207,8 @@ fn end_to_end () {
info! ("Shutting down end-to-end test"); info! ("Shutting down end-to-end test");
stop_server_tx.send (()).expect ("Couldn't shut down server"); testing_server.graceful_shutdown ().await;
stop_relay_tx.send (()).expect ("Couldn't shut down relay"); testing_relay.graceful_shutdown ().await;
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");
}); });
} }
@ -268,11 +224,10 @@ fn debug_proxy () {
// Start relay // Start relay
let server_name = "aliens_wildland"; let server_name = "aliens_wildland";
let api_key = "AnacondaHardcoverGrannyUnlatchLankinessMutate";
let testing_config = TestingConfig { let testing_config = TestingConfig {
server_name, server_name,
api_key, api_key: "AnacondaHardcoverGrannyUnlatchLankinessMutate",
proxy_port, proxy_port,
relay_port, relay_port,