mirror of
https://github.com/YGGverse/agate.git
synced 2026-04-08 12:35:28 +00:00
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.
This commit is contained in:
parent
e1d808a790
commit
3c6684d54c
1 changed files with 11 additions and 5 deletions
|
|
@ -6,11 +6,17 @@ use url::Url;
|
||||||
|
|
||||||
static BINARY_PATH: &'static str = env!("CARGO_BIN_EXE_agate");
|
static BINARY_PATH: &'static str = env!("CARGO_BIN_EXE_agate");
|
||||||
|
|
||||||
fn addr() -> SocketAddr {
|
fn addr(port: u16) -> SocketAddr {
|
||||||
"[::1]:1965".to_socket_addrs().unwrap().next().unwrap()
|
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
|
// start the server
|
||||||
let mut server = Command::new(BINARY_PATH)
|
let mut server = Command::new(BINARY_PATH)
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
|
|
@ -32,7 +38,7 @@ fn get(args: &[&str], url: &str) -> Result<Page, anyhow::Error> {
|
||||||
// actually perform the request
|
// actually perform the request
|
||||||
let page = tokio::runtime::Runtime::new()
|
let page = tokio::runtime::Runtime::new()
|
||||||
.unwrap()
|
.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
|
// try to stop the server again
|
||||||
match server.try_wait() {
|
match server.try_wait() {
|
||||||
|
|
@ -57,7 +63,7 @@ fn get(args: &[&str], url: &str) -> Result<Page, anyhow::Error> {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn index_page() {
|
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!(
|
assert_eq!(
|
||||||
page.header,
|
page.header,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue