-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
test_multi_node.py
66 lines (56 loc) · 2.01 KB
/
test_multi_node.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import os
import sys
from unittest import mock
import pytest
from tests_examples_app.public import _PATH_EXAMPLES
from lightning_app.testing.testing import application_testing, LightningTestApp
class LightningTestMultiNodeApp(LightningTestApp):
def on_before_run_once(self):
res = super().on_before_run_once()
if self.works and all(w.has_stopped for w in self.works):
assert len([w for w in self.works]) == 2
return True
return res
@pytest.mark.skip(reason="flaky")
@mock.patch("lightning_app.components.multi_node.base.is_running_in_cloud", return_value=True)
def test_multi_node_example(_, monkeypatch):
monkeypatch.chdir(os.path.join(_PATH_EXAMPLES, "app_multi_node"))
command_line = [
"app.py",
"--blocking",
"False",
"--open-ui",
"False",
]
result = application_testing(LightningTestMultiNodeApp, command_line)
assert result.exit_code == 0
class LightningTestMultiNodeWorksApp(LightningTestApp):
def on_before_run_once(self):
res = super().on_before_run_once()
if self.works and all(w.has_stopped for w in self.works):
assert len([w for w in self.works]) == 2
return True
return res
@pytest.mark.parametrize(
"app_name",
[
"train_pytorch.py",
"train_any.py",
# "app_lite_work.py",
"train_pytorch_spawn.py",
# "app_pl_work.py": TODO Add once https://github.com/Lightning-AI/lightning/issues/15556 is resolved.
],
)
@pytest.mark.skipif(sys.platform == "win32", reason="flaky")
@mock.patch("lightning_app.components.multi_node.base.is_running_in_cloud", return_value=True)
def test_multi_node_examples(_, app_name, monkeypatch):
monkeypatch.chdir(os.path.join(_PATH_EXAMPLES, "app_multi_node"))
command_line = [
app_name,
"--blocking",
"False",
"--open-ui",
"False",
]
result = application_testing(LightningTestMultiNodeWorksApp, command_line)
assert result.exit_code == 0