|
5 | 5 | import pytest
|
6 | 6 |
|
7 | 7 | from lightning.app import LightningApp, LightningFlow, LightningWork
|
| 8 | +from lightning.app.core import constants |
8 | 9 | from lightning.app.frontend import StaticWebFrontend, StreamlitFrontend
|
9 | 10 | from lightning.app.runners import MultiProcessRuntime
|
10 | 11 | from lightning.app.utilities.component import _get_context
|
@@ -46,15 +47,34 @@ def run(self):
|
46 | 47 | self.stop()
|
47 | 48 |
|
48 | 49 |
|
| 50 | +@pytest.mark.parametrize( |
| 51 | + "cloudspace_host, port, expected_host, expected_target", |
| 52 | + [ |
| 53 | + (None, 7000, "localhost", "http://localhost:7000"), |
| 54 | + ("test.lightning.ai", 7000, "0.0.0.0", "https://7000-test.lightning.ai"), |
| 55 | + ], |
| 56 | +) |
49 | 57 | @mock.patch("lightning.app.runners.multiprocess.find_free_network_port")
|
50 |
| -def test_multiprocess_starts_frontend_servers(*_): |
| 58 | +def test_multiprocess_starts_frontend_servers( |
| 59 | + mock_find_free_network_port, monkeypatch, cloudspace_host, port, expected_host, expected_target |
| 60 | +): |
51 | 61 | """Test that the MultiProcessRuntime starts the servers for the frontends in each LightningFlow."""
|
| 62 | + |
| 63 | + monkeypatch.setattr(constants, "LIGHTNING_CLOUDSPACE_HOST", cloudspace_host) |
| 64 | + mock_find_free_network_port.return_value = port |
| 65 | + |
52 | 66 | root = StartFrontendServersTestFlow()
|
53 | 67 | app = LightningApp(root)
|
54 | 68 | MultiProcessRuntime(app).dispatch()
|
55 | 69 |
|
56 | 70 | app.frontends[root.flow0.name].start_server.assert_called_once()
|
| 71 | + assert app.frontends[root.flow0.name].start_server.call_args.kwargs["host"] == expected_host |
| 72 | + |
57 | 73 | app.frontends[root.flow1.name].start_server.assert_called_once()
|
| 74 | + assert app.frontends[root.flow1.name].start_server.call_args.kwargs["host"] == expected_host |
| 75 | + |
| 76 | + assert app.frontends[root.flow0.name].flow._layout["target"] == f"{expected_target}/{root.flow0.name}" |
| 77 | + assert app.frontends[root.flow1.name].flow._layout["target"] == f"{expected_target}/{root.flow1.name}" |
58 | 78 |
|
59 | 79 | app.frontends[root.flow0.name].stop_server.assert_called_once()
|
60 | 80 | app.frontends[root.flow1.name].stop_server.assert_called_once()
|
|
0 commit comments