Skip to content

Commit 0809112

Browse files
author
Arun Persaud
committed
add integration test
1 parent 152b58b commit 0809112

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

tests/integration/test_dev_server_serve.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,71 @@
88
from nikola.utils import base_path_from_siteuri
99
from .dev_server_test_helper import MyFakeSite, SERVER_ADDRESS, find_unused_port, LOGGER, OUTPUT_FOLDER
1010

11+
def test_two_serves_with_different_port( site_and_base_path: Tuple[MyFakeSite, str], expected_text: str
12+
):
13+
site, base_path = site_and_base_path
14+
command_serveA = serve.CommandServe()
15+
command_serveA.set_site(site)
16+
command_serveB = serve.CommandServe()
17+
command_serveB.set_site(site)
18+
with ThreadPoolExecutor(max_workers=2) as executor:
19+
options = {
20+
"address": SERVER_ADDRESS,
21+
"port": find_unused_port(),
22+
"browser": False,
23+
"detach": False,
24+
"ipv6": False,
25+
}
26+
future_to_run_web_serverA = executor.submit(lambda: command_serveA.execute(options=options))
27+
options = {
28+
"address": SERVER_ADDRESS,
29+
"port": find_unused_port(),
30+
"browser": False,
31+
"detach": False,
32+
"ipv6": False,
33+
}
34+
future_to_run_web_serverB = executor.submit(lambda: command_serveB.execute(options=options))
35+
sleep(0.1)
36+
try:
37+
command_serveA.shutdown()
38+
future_to_run_web_serverA.result()
39+
except SystemExit as e:
40+
assert e.code == 0
41+
try:
42+
command_serveB.shutdown()
43+
future_to_run_web_serverB.result()
44+
except SystemExit as e:
45+
assert e.code == 0
46+
47+
def test_two_serves_with_same_port( site_and_base_path: Tuple[MyFakeSite, str], expected_text: str
48+
):
49+
site, base_path = site_and_base_path
50+
command_serveA = serve.CommandServe()
51+
command_serveA.set_site(site)
52+
command_serveB = serve.CommandServe()
53+
command_serveB.set_site(site)
54+
port = find_unused_port()
55+
with ThreadPoolExecutor(max_workers=2) as executor:
56+
options = {
57+
"address": SERVER_ADDRESS,
58+
"port": port,
59+
"browser": False,
60+
"detach": False,
61+
"ipv6": False,
62+
}
63+
future_to_run_web_serverA = executor.submit(lambda: command_serveA.execute(options=options))
64+
future_to_run_web_serverB = executor.submit(lambda: command_serveB.execute(options=options))
65+
sleep(0.1)
66+
try:
67+
command_serveA.shutdown()
68+
future_to_run_web_serverA.result()
69+
except SystemExit as e:
70+
assert e.code == 0
71+
try:
72+
command_serveB.shutdown()
73+
future_to_run_web_serverB.result()
74+
except SystemExit as e:
75+
assert e.code == 1
1176

1277
def test_serves_root_dir(
1378
site_and_base_path: Tuple[MyFakeSite, str], expected_text: str

0 commit comments

Comments
 (0)