Skip to content

Commit 378f72b

Browse files
Ensure each Civilisation only ever has one server open
1 parent 421a66a commit 378f72b

3 files changed

Lines changed: 39 additions & 7 deletions

File tree

toolproof/src/civilization.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,8 @@ pub struct Civilization<'u> {
3737
}
3838

3939
impl<'u> Civilization<'u> {
40-
pub async fn shutdown(self) {
41-
for handle in &self.handles {
42-
handle.stop(false).await;
43-
}
44-
for thread in &self.threads {
45-
thread.abort();
46-
}
40+
pub async fn shutdown(mut self) {
41+
self.stop_servers().await;
4742

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

5752
impl<'u> Civilization<'u> {
53+
pub async fn stop_servers(&mut self) {
54+
for handle in self.handles.drain(..) {
55+
handle.stop(false).await;
56+
}
57+
for thread in self.threads.drain(..) {
58+
thread.abort();
59+
}
60+
self.purge_port();
61+
}
62+
5863
pub fn ensure_port(&mut self) -> u16 {
5964
if self.assigned_server_port.is_none() {
6065
self.assigned_server_port = pick_unused_port();

toolproof/src/definitions/hosting/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ mod host_dir {
1414
use super::*;
1515

1616
async fn host(dir: &String, civ: &mut Civilization<'_>) -> Result<(), ToolproofStepError> {
17+
civ.stop_servers().await;
18+
1719
let mut attempts = 0;
1820
let mut running = false;
1921
while !running && attempts < 5 {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Browser can serve a directory twice in one test
2+
3+
steps:
4+
- step: I have a "my_test.toolproof.yml" file with the content {yaml}
5+
yaml: |-
6+
name: Inner serve twice test
7+
8+
steps:
9+
- I have a "public/index.html" file with the content "<p>First</p>"
10+
- I serve the directory "public"
11+
- In my browser, I load "/"
12+
- step: In my browser, I evaluate {js}
13+
js: |-
14+
toolproof.assert_eq(document.querySelector("p").innerText, "First");
15+
- I have a "public2/index.html" file with the content "<p>Second</p>"
16+
- I serve the directory "public2"
17+
- In my browser, I load "/"
18+
- step: In my browser, I evaluate {js}
19+
js: |-
20+
toolproof.assert_eq(document.querySelector("p").innerText, "Second");
21+
- I run "%toolproof_path% --timeout 60"
22+
- step: "stdout should contain 'Total passing tests: 1'"
23+
- step: "stdout should contain 'Failing tests: 0'"
24+
- step: "stdout should contain 'All tests passed'"
25+
- stderr should be empty

0 commit comments

Comments
 (0)