commit 3c6684d54c3b065467f393d8d252ecbb1e915dfa
parent e1d808a79086607192c29d95182514e7f5c4979a
Author: Johann150 <johann.galle@protonmail.com>
Date: Sat, 20 Feb 2021 10:22:12 +0100
allow for parallel tests
By default the libtest test harness runs multiple tests in parallel.
This makes tests fail because the server port is already occupied by another port.
Diffstat:
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/tests/tests.rs b/tests/tests.rs
@@ -6,11 +6,17 @@ use url::Url;
static BINARY_PATH: &'static str = env!("CARGO_BIN_EXE_agate");
-fn addr() -> SocketAddr {
- "[::1]:1965".to_socket_addrs().unwrap().next().unwrap()
+fn addr(port: u16) -> SocketAddr {
+ use std::net::{IpAddr, Ipv4Addr};
+
+ (IpAddr::V4(Ipv4Addr::LOCALHOST), port)
+ .to_socket_addrs()
+ .unwrap()
+ .next()
+ .unwrap()
}
-fn get(args: &[&str], url: &str) -> Result<Page, anyhow::Error> {
+fn get(args: &[&str], addr: SocketAddr, url: &str) -> Result<Page, anyhow::Error> {
// start the server
let mut server = Command::new(BINARY_PATH)
.stderr(Stdio::piped())
@@ -32,7 +38,7 @@ fn get(args: &[&str], url: &str) -> Result<Page, anyhow::Error> {
// actually perform the request
let page = tokio::runtime::Runtime::new()
.unwrap()
- .block_on(async { Page::fetch_from(&Url::parse(url).unwrap(), addr(), None).await });
+ .block_on(async { Page::fetch_from(&Url::parse(url).unwrap(), addr, None).await });
// try to stop the server again
match server.try_wait() {
@@ -57,7 +63,7 @@ fn get(args: &[&str], url: &str) -> Result<Page, anyhow::Error> {
#[test]
fn index_page() {
- let page = get(&[], "gemini://localhost").expect("could not get page");
+ let page = get(&[], addr(1965), "gemini://localhost").expect("could not get page");
assert_eq!(
page.header,