Skip to content

Commit

Permalink
dedicated test
Browse files Browse the repository at this point in the history
  • Loading branch information
burnout87 committed Oct 7, 2024
1 parent 59caad5 commit 238c4d4
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/test_server_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import shutil
import urllib
import io
from os import close

import requests
import time
import uuid
Expand All @@ -11,6 +13,7 @@
import jwt
import glob
import pytest
import fcntl
from datetime import datetime, timedelta
from dateutil import parser, tz
from functools import reduce
Expand Down Expand Up @@ -320,6 +323,55 @@ def test_error_two_scratch_dir_same_job_id(dispatcher_live_fixture):
os.rmdir(fake_scratch_dir)


@pytest.mark.not_safe_parallel
@pytest.mark.fast
def test_scratch_dir_creation_lock_error(dispatcher_live_fixture):
DispatcherJobState.remove_scratch_folders()
server = dispatcher_live_fixture
logger.info("constructed server: %s", server)

encoded_token = jwt.encode(default_token_payload, secret_key, algorithm='HS256')
# issuing a request each, with the same set of parameters
params = dict(
query_status="new",
query_type="Real",
instrument="empty-async",
product_type="dummy",
token=encoded_token
)
DataServerQuery.set_status('submitted')
# let's generate a fake scratch dir
jdata = ask(server,
params,
expected_query_status=["submitted"],
max_time_s=50,
)

job_id = jdata['job_monitor']['job_id']
session_id = jdata['session_id']
fake_scratch_dir = f'scratch_sid_01234567890_jid_{job_id}'
os.makedirs(fake_scratch_dir)

params['job_id'] = job_id
params['session_id'] = session_id

lock_file = f".lock_{job_id}"

with open(lock_file, 'w') as f_lock:
fcntl.flock(f_lock, fcntl.LOCK_EX)

jdata = ask(server,
params,
expected_status_code=500,
expected_query_status=None,
)
scratch_dir_retry_attempts = 5
assert jdata['error'] == f"InternalError():Failed to acquire lock for directory creation after {scratch_dir_retry_attempts} attempts."
assert jdata['error_message'] == f"Failed to acquire lock for directory creation after {scratch_dir_retry_attempts} attempts."
os.rmdir(fake_scratch_dir)
os.remove(lock_file)


@pytest.mark.fast
def test_same_request_different_users(dispatcher_live_fixture):
server = dispatcher_live_fixture
Expand Down

0 comments on commit 238c4d4

Please sign in to comment.