Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track test environment setup in redis #468

Merged
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All notable changes to this project will be documented here.

- Fix bug that prevented test results from being returned when a feedback file could not be found (#458)
- Add support for Python 3.11 and 3.12 (#467)
- Track test environment setup status and report errors when running tests if environment setup is in progress or raised an error (#468)

## [v2.3.1]
- Fix a bug that prevented test file from being copied from a zip file to another location on disk (#426)
Expand Down
13 changes: 12 additions & 1 deletion client/autotest_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,17 @@ def update_settings(settings_id, user):
@app.route("/settings/<settings_id>/test", methods=["PUT"])
@authorize
def run_tests(settings_id, user):
test_settings = json.loads(REDIS_CONNECTION.hget("autotest:settings", key=settings_id))
env_status = test_settings.get("_env_status")
if env_status == "setup":
raise Exception("Setting up test environment. Please try again later.")
elif env_status == "error":
msg = "Settings Error"
settings_error = test_settings.get("_error", "")
if settings_error:
msg += f": {settings_error}"
raise Exception(msg)

test_data = request.json["test_data"]
categories = request.json["categories"]
high_priority = request.json.get("request_high_priority")
Expand All @@ -221,7 +232,7 @@ def run_tests(settings_id, user):

timeout = 0

for settings_ in settings(settings_id)["testers"]:
for settings_ in test_settings["testers"]:
for data in settings_["test_data"]:
timeout += data["timeout"]

Expand Down
12 changes: 10 additions & 2 deletions server/autotest_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ def _run_test_specs(
timeout_expired = None
timeout = test_data.get("timeout")
try:
env_vars = {**os.environ, **_get_env_vars(test_username), **settings["_env"]}
env = settings.get("_env", {})
env_vars = {**os.environ, **_get_env_vars(test_username), **env}
env_vars = _update_env_vars(env_vars, test_env_vars)
proc = subprocess.Popen(
args,
Expand All @@ -216,7 +217,7 @@ def _run_test_specs(
stdin=subprocess.PIPE,
preexec_fn=set_rlimits_before_test,
universal_newlines=True,
env={**os.environ, **env_vars, **settings["_env"]},
env={**os.environ, **env_vars, **env},
)
try:
settings_json = json.dumps({**settings, "test_data": test_data})
Expand Down Expand Up @@ -359,6 +360,11 @@ def ignore_missing_dir_error(


def update_test_settings(user, settings_id, test_settings, file_url):
test_settings["_user"] = user
test_settings["_last_access"] = int(time.time())
test_settings["_env_status"] = "setup"
redis_connection().hset("autotest:settings", key=settings_id, value=json.dumps(test_settings))

try:
settings_dir = os.path.join(TEST_SCRIPT_DIR, str(settings_id))

Expand Down Expand Up @@ -391,8 +397,10 @@ def update_test_settings(user, settings_id, test_settings, file_url):
test_settings["testers"][i] = tester_settings
test_settings["_files"] = files_dir
test_settings.pop("_error", None)
test_settings["_env_status"] = "ready"
except Exception as e:
test_settings["_error"] = str(e)
test_settings["_env_status"] = "error"
raise
finally:
test_settings["_user"] = user
Expand Down
Loading