Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 11 additions & 29 deletions python/tests/test_sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os
import socket
import sys
import threading
import time

import pytest
Expand Down Expand Up @@ -267,46 +266,29 @@ def test_throttle_result_correct(self):


class TestPauseResume:
def test_pause_resume_from_thread(self):
def test_pause_resume(self):
sb = _policy()

def run_in_thread():
return sb.run(["python3", "-c",
"import time\n"
"for i in range(5):\n"
" print(i, flush=True)\n"
" time.sleep(0.1)\n"
])

t = threading.Thread(target=run_in_thread)
t.start()
time.sleep(0.15) # let it start
sb.spawn(["python3", "-c",
"import time\n"
"for i in range(5):\n"
" print(i, flush=True)\n"
" time.sleep(0.1)\n"
])

sb.pause()
time.sleep(0.3) # paused should not progress
time.sleep(0.3) # paused, should not progress
sb.resume()

t.join(timeout=10)
# Process should have completed after resume
sb.wait()

def test_pid_available_during_run(self):
sb = _policy()
pid_seen = []

def run_in_thread():
sb.run(["sleep", "1"])

t = threading.Thread(target=run_in_thread)
t.start()
time.sleep(0.1)
sb.spawn(["sleep", "1"])

pid = sb.pid
assert pid is not None
assert pid > 0
pid_seen.append(pid)

# After run completes, pid should be None
t.join(timeout=10)
sb.wait()
assert sb.pid is None

def test_pause_not_running_raises(self):
Expand Down
Loading