Skip to content

Commit 833871f

Browse files
committed
Added some tests for issue 387. They are run in a separate process on
purpose.
1 parent 83363fb commit 833871f

File tree

6 files changed

+119
-0
lines changed

6 files changed

+119
-0
lines changed

tests/test_issue_387_1.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import os
2+
import subprocess
3+
import sys
4+
5+
import pytest
6+
7+
8+
@pytest.mark.timeout(5)
9+
def test_issue_387_1() -> None:
10+
subprocess.run([sys.executable, os.path.abspath(__file__)[:-2] + '.run'],
11+
shell=True, check=True, capture_output=True)

tests/test_issue_387_1.run

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import logging
2+
import os
3+
from multiprocessing import Process, set_start_method
4+
from threading import Thread
5+
6+
import psij
7+
8+
9+
def func():
10+
# Get logs from PSI/J
11+
logger = logging.getLogger()
12+
logger.setLevel("DEBUG")
13+
logger.addHandler(logging.StreamHandler())
14+
15+
exe = psij.JobExecutor.get_instance("local")
16+
job = psij.Job(psij.JobSpec("test", "echo", arguments=["foo"]))
17+
exe.submit(job)
18+
print(job, flush=True)
19+
20+
# This hangs on the second round
21+
job.wait()
22+
print(job, flush=True)
23+
24+
25+
def fn():
26+
print(os.getpid())
27+
28+
29+
if __name__ == "__main__":
30+
Thread(target=fn).start()
31+
set_start_method("fork")
32+
p = Process(target=func)
33+
p.start()
34+
p.join()
35+
36+
print("Done, and again...")
37+
38+
p = Process(target=func)
39+
p.start()
40+
p.join()

tests/test_issue_387_2.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import os
2+
import subprocess
3+
import sys
4+
5+
import pytest
6+
7+
8+
@pytest.mark.timeout(5)
9+
def test_issue_387_2() -> None:
10+
subprocess.run([sys.executable, os.path.abspath(__file__)[:-2] + '.run'],
11+
shell=True, check=True, capture_output=True)

tests/test_issue_387_2.run

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import logging
2+
from threading import Thread
3+
import psij
4+
5+
6+
def func():
7+
# Get logs from PSI/J
8+
logger = logging.getLogger()
9+
logger.setLevel("DEBUG")
10+
logger.addHandler(logging.StreamHandler())
11+
12+
exe = psij.JobExecutor.get_instance("local")
13+
job = psij.Job(psij.JobSpec("test", "echo", arguments=["foo"]))
14+
exe.submit(job)
15+
16+
# This hangs
17+
job.wait()
18+
19+
if __name__ == "__main__":
20+
p = Thread(target=func)
21+
p.start()
22+
p.join()
23+

tests/test_issue_387_3.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import os
2+
import subprocess
3+
import sys
4+
5+
import pytest
6+
7+
8+
@pytest.mark.timeout(5)
9+
def test_issue_387_3() -> None:
10+
subprocess.run([sys.executable, os.path.abspath(__file__)[:-2] + '.run'],
11+
shell=True, check=True, capture_output=True)

tests/test_issue_387_3.run

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import logging
2+
from threading import Thread
3+
import psij
4+
5+
6+
def func():
7+
# Get logs from PSI/J
8+
logger = logging.getLogger()
9+
logger.setLevel("DEBUG")
10+
logger.addHandler(logging.StreamHandler())
11+
12+
exe = psij.JobExecutor.get_instance("local")
13+
job = psij.Job(psij.JobSpec("test", "echo", arguments=["foo"]))
14+
exe.submit(job)
15+
16+
# This hangs
17+
job.wait()
18+
19+
if __name__ == "__main__":
20+
p = Thread(target=func)
21+
p.start()
22+
p.join()
23+

0 commit comments

Comments
 (0)