Skip to content

Commit

Permalink
prevent tests from hanging
Browse files Browse the repository at this point in the history
  • Loading branch information
magland committed Oct 24, 2023
1 parent c69fab1 commit e45e0c5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions python/protocaas/compute_resource/start_compute_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,15 @@ def __init__(self):
)
else:
self._pubsub_client = None
def start(self, *, timeout: Optional[float] = None): # timeout is used for testing
def start(self, *, timeout: Optional[float] = None, cleanup_old_jobs=True): # timeout is used for testing
timer_handle_jobs = 0

# Start cleaning up old job directories
# It's important to do this in a separate process
# because it can take a long time to delete all the files in the tmp directories (remfile is the culprit)
# and we don't want to block the main process from handling jobs
multiprocessing.Process(target=_cleanup_old_job_working_directories, args=(os.getcwd() + '/jobs',)).start()
if cleanup_old_jobs:
multiprocessing.Process(target=_cleanup_old_job_working_directories, args=(os.getcwd() + '/jobs',)).start()

print('Starting compute resource')
overall_timer = time.time()
Expand Down Expand Up @@ -271,7 +272,7 @@ def _load_apps(*, compute_resource_id: str, compute_resource_private_key: str, c
ret.append(app)
return ret

def start_compute_resource(dir: str, *, timeout: Optional[float] = None): # timeout is used for testing
def start_compute_resource(dir: str, *, timeout: Optional[float] = None, cleanup_old_jobs=True): # timeout is used for testing
config_fname = os.path.join(dir, '.protocaas-compute-resource-node.yaml')

if os.path.exists(config_fname):
Expand All @@ -284,7 +285,7 @@ def start_compute_resource(dir: str, *, timeout: Optional[float] = None): # time
os.environ[k] = the_config[k]

daemon = Daemon()
daemon.start(timeout=timeout)
daemon.start(timeout=timeout, cleanup_old_jobs=cleanup_old_jobs)

def get_pubsub_subscription(*, compute_resource_id: str, compute_resource_private_key: str, compute_resource_node_name: Optional[str] = None, compute_resource_node_id: Optional[str] = None):
url_path = f'/api/compute_resource/compute_resources/{compute_resource_id}/pubsub_subscription'
Expand Down
2 changes: 1 addition & 1 deletion python/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ async def test_api():
job = resp.job
assert job.status == 'finished'

start_compute_resource(dir=tmpdir, timeout=0.1)
start_compute_resource(dir=tmpdir, timeout=0.1, cleanup_old_jobs=False)

# gui: Delete job
resp = await delete_job(job_id=job_id, github_access_token=github_access_token)
Expand Down

0 comments on commit e45e0c5

Please sign in to comment.