|
8 | 8 | from nikola.utils import base_path_from_siteuri
|
9 | 9 | from .dev_server_test_helper import MyFakeSite, SERVER_ADDRESS, find_unused_port, LOGGER, OUTPUT_FOLDER
|
10 | 10 |
|
| 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 |
11 | 76 |
|
12 | 77 | def test_serves_root_dir(
|
13 | 78 | site_and_base_path: Tuple[MyFakeSite, str], expected_text: str
|
|
0 commit comments