Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

## Unreleased

* No changes (CI release improvements)
* Ensure only one hosting server exists at a time within a test context. A server hosted in a previous step will now be closed when starting another.

## v0.17.1 (April 1, 2026)

Expand Down
19 changes: 12 additions & 7 deletions toolproof/src/civilization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,8 @@ pub struct Civilization<'u> {
}

impl<'u> Civilization<'u> {
pub async fn shutdown(self) {
for handle in &self.handles {
handle.stop(false).await;
}
for thread in &self.threads {
thread.abort();
}
pub async fn shutdown(mut self) {
self.stop_servers().await;

if let Some(BrowserWindow::Chrome(window)) = self.window {
window
Expand All @@ -55,6 +50,16 @@ impl<'u> Civilization<'u> {
}

impl<'u> Civilization<'u> {
pub async fn stop_servers(&mut self) {
for handle in self.handles.drain(..) {
handle.stop(false).await;
}
for thread in self.threads.drain(..) {
thread.abort();
}
self.purge_port();
}

pub fn ensure_port(&mut self) -> u16 {
if self.assigned_server_port.is_none() {
self.assigned_server_port = pick_unused_port();
Expand Down
2 changes: 2 additions & 0 deletions toolproof/src/definitions/hosting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ mod host_dir {
use super::*;

async fn host(dir: &String, civ: &mut Civilization<'_>) -> Result<(), ToolproofStepError> {
civ.stop_servers().await;

let mut attempts = 0;
let mut running = false;
while !running && attempts < 5 {
Expand Down
25 changes: 25 additions & 0 deletions toolproof/test_suite/browser/serve_twice.toolproof.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Browser can serve a directory twice in one test

steps:
- step: I have a "my_test.toolproof.yml" file with the content {yaml}
yaml: |-
name: Inner serve twice test

steps:
- I have a "public/index.html" file with the content "<p>First</p>"
- I serve the directory "public"
- In my browser, I load "/"
- step: In my browser, I evaluate {js}
js: |-
toolproof.assert_eq(document.querySelector("p").innerText, "First");
- I have a "public2/index.html" file with the content "<p>Second</p>"
- I serve the directory "public2"
- In my browser, I load "/"
- step: In my browser, I evaluate {js}
js: |-
toolproof.assert_eq(document.querySelector("p").innerText, "Second");
- I run "%toolproof_path% --timeout 60"
- step: "stdout should contain 'Total passing tests: 1'"
- step: "stdout should contain 'Failing tests: 0'"
- step: "stdout should contain 'All tests passed'"
- stderr should be empty
Loading