Skip to content

Commit

Permalink
Merge pull request #534 from pretendWhale/v2.4.4
Browse files Browse the repository at this point in the history
V2.4.4
  • Loading branch information
donny-wong authored Jul 4, 2024
2 parents 5bcf5b0 + ffb97b3 commit 13f2b63
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 21 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/test_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
jobs:
test:
if: github.event.pull_request.draft == false
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
matrix:
python-version:
Expand Down Expand Up @@ -35,6 +35,10 @@ jobs:
restore-keys: |
${{ runner.os }}-pip-
- name: Install python packages
run: python -m pip install pytest fakeredis -r ${{ matrix.test-dir }}/requirements.txt
run: python -m pip install pytest fakeredis typing-extensions -r ${{ matrix.test-dir }}/requirements.txt
- name: Create users
run: |
sudo adduser --disabled-login --no-create-home fake_user
sudo adduser --disabled-login --no-create-home fake_user_2
- name: run tests
run: pytest ${{ matrix.test-dir }}
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# CHANGELOG
All notable changes to this project will be documented here.

## [v2.4.4]
- Add tidyverse as a default R tester package (#512)
- For the Haskell tester, make stack resolver a test setting (#526)
- Clean up tmp directory after test runs (#528)

## [v2.4.3]
- Omit skipped test cases in Python tester (#522)

Expand Down
6 changes: 3 additions & 3 deletions client/.dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ ARG UBUNTU_VERSION
FROM ubuntu:$UBUNTU_VERSION

RUN apt-get update -y && \
apt-get -y install software-properties-common && \
add-apt-repository -y ppa:deadsnakes/ppa && \
apt-get install -y python3.11 python3.11-venv
DEBIAN_FRONTEND=noninteractive apt-get -y install software-properties-common && \
DEBIAN_FRONTEND=noninteractive add-apt-repository -y ppa:deadsnakes/ppa && \
DEBIAN_FRONTEND=noninteractive apt-get install -y python3.11 python3.11-venv

COPY ./requirements.txt /requirements.txt

Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
context: ./server
dockerfile: ./.dockerfiles/Dockerfile
args:
UBUNTU_VERSION: '20.04'
UBUNTU_VERSION: '22.04'
LOGIN_USER: 'docker'
WORKSPACE: '/home/docker/.autotesting'
image: markus-autotest-server-dev:1.1.0
Expand All @@ -28,7 +28,7 @@ services:
context: ./client
dockerfile: ./.dockerfiles/Dockerfile
args:
UBUNTU_VERSION: '20.04'
UBUNTU_VERSION: '22.04'
image: markus-autotest-client-dev:1.1.0
container_name: 'autotest-client'
volumes:
Expand Down
22 changes: 17 additions & 5 deletions server/.dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ ARG UBUNTU_VERSION

FROM ubuntu:$UBUNTU_VERSION as base

ENV DEBIAN_FRONTEND=noninteractive

ARG LOGIN_USER
ARG WORKSPACE

RUN apt-get update -y && \
apt-get -y install software-properties-common && \
add-apt-repository -y ppa:deadsnakes/ppa && \
apt-get -y install python3.7 \
DEBIAN_FRONTEND=noninteractive apt-get -y install software-properties-common && \
DEBIAN_FRONTEND=noninteractive add-apt-repository -y ppa:deadsnakes/ppa && \
DEBIAN_FRONTEND=noninteractive apt-get -y install python3.7 \
python3.7-venv \
python3.8 \
python3.8-venv \
Expand All @@ -26,7 +25,16 @@ RUN apt-get update -y && \
postgresql-client \
libpq-dev \
sudo \
git
git \
libfontconfig1-dev \
libcurl4-openssl-dev \
libfreetype6-dev \
libpng-dev \
libtiff5-dev \
libjpeg-dev \
libharfbuzz-dev \
libfribidi-dev \
r-base

RUN useradd -ms /bin/bash $LOGIN_USER && \
usermod -aG sudo $LOGIN_USER && \
Expand All @@ -36,6 +44,8 @@ RUN useradd -ms /bin/bash $LOGIN_USER && \
usermod -aG $worker $LOGIN_USER; \
done

RUN chmod a+x /home/${LOGIN_USER}

COPY . /app

RUN python3.11 -m venv /markus_venv && \
Expand All @@ -44,6 +54,8 @@ RUN python3.11 -m venv /markus_venv && \
find /app/autotest_server/testers -name requirements.system -exec {} \; && \
rm -rf /app/*

RUN echo "TZ=$( cat /etc/timezone )" >> /etc/R/Renviron.site

RUN mkdir -p ${WORKSPACE} && chown ${LOGIN_USER} ${WORKSPACE}

WORKDIR /home/${LOGIN_USER}
Expand Down
8 changes: 7 additions & 1 deletion server/autotest_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,19 @@ def _run_test_specs(

def _clear_working_directory(tests_path: str, test_username: str) -> None:
"""
Run commands that clear the tests_path working directory
Run commands that clear the tests_path working directory, as well
as clearing any files or directories owned by test_username in the /tmp directory
"""
if test_username != getpass.getuser():
sticky_cmd = f"sudo -u {test_username} -- bash -c 'chmod -Rf -t {tests_path}'"
chmod_cmd = f"sudo -u {test_username} -- bash -c 'chmod -Rf ugo+rwX {tests_path}'"
clean_tmp_cmd = (
f"sudo -u {test_username} -- bash -c 'find /tmp -maxdepth 1 -user {test_username} -exec rm " f"-rf {{}} +' "
)
else:
sticky_cmd = f"chmod -Rf -t {tests_path}"
chmod_cmd = f"chmod -Rf ugo+rwX {tests_path}"
clean_tmp_cmd = f"find /tmp -maxdepth 1 -user {test_username} -exec rm -rf {{}} +"

subprocess.run(sticky_cmd, shell=True)
subprocess.run(chmod_cmd, shell=True)
Expand All @@ -268,6 +273,7 @@ def _clear_working_directory(tests_path: str, test_username: str) -> None:
# set the group ownership with sudo (and that is only done in ../install.sh)
clean_cmd = f"rm -rf {tests_path}/.[!.]* {tests_path}/*"
subprocess.run(clean_cmd, shell=True)
subprocess.run(clean_tmp_cmd, shell=True)


def _stop_tester_processes(test_username: str) -> None:
Expand Down
4 changes: 2 additions & 2 deletions server/autotest_server/testers/haskell/haskell_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from ..tester import Tester, Test, TestError
from ..specs import TestSpecs

STACK_OPTIONS = ["--resolver=lts-14.27", "--system-ghc", "--allow-different-user"]


class HaskellTest(Test):
def __init__(
Expand Down Expand Up @@ -101,6 +99,8 @@ def run_haskell_tests(self) -> Dict[str, List[Dict[str, Union[int, str]]]]:
Tests are run by first discovering all tests from a specific module (using tasty-discover)
and then running all the discovered tests and parsing the results from a csv file.
"""
resolver = self.specs["env_data", "resolver_version"]
STACK_OPTIONS = [f"--resolver={resolver}", "--system-ghc", "--allow-different-user"]
results = {}
this_dir = os.getcwd()
haskell_lib = os.path.join(os.path.dirname(os.path.realpath(__file__)), "lib")
Expand Down
17 changes: 17 additions & 0 deletions server/autotest_server/testers/haskell/settings_schema.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
{
"type": "object",
"required": [
"env_data"
],
"properties": {
"tester_type": {
"type": "string",
"enum": [
"haskell"
]
},
"env_data": {
"title": "Haskell environment",
"type": "object",
"required": [
"resolver_version"
],
"properties": {
"resolver_version": {
"title": "Resolver version",
"type": "string",
"default": null
}
}
},
"test_data": {
"title": "Test Groups",
"type": "array",
Expand Down
16 changes: 13 additions & 3 deletions server/autotest_server/testers/haskell/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
import json
import subprocess


HASKELL_TEST_DEPS = ["tasty-discover", "tasty-quickcheck"]
STACK_RESOLVER = "lts-16.17"


def create_environment(_settings, _env_dir, default_env_dir):
resolver = "lts-14.27"
env_data = _settings.get("env_data", {})
resolver = env_data.get("resolver_version", STACK_RESOLVER)
cmd = ["stack", "build", "--resolver", resolver, "--system-ghc", *HASKELL_TEST_DEPS]
subprocess.run(cmd, check=True)

Expand All @@ -16,8 +17,17 @@ def create_environment(_settings, _env_dir, default_env_dir):

def install():
subprocess.run(os.path.join(os.path.dirname(os.path.realpath(__file__)), "requirements.system"), check=True)
resolver = STACK_RESOLVER
cmd = ["stack", "build", "--resolver", resolver, "--system-ghc", *HASKELL_TEST_DEPS]
subprocess.run(cmd, check=True)
subprocess.run(
os.path.join(os.path.dirname(os.path.realpath(__file__)), "stack_permissions.sh"), check=True, shell=True
)


def settings():
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), "settings_schema.json")) as f:
return json.load(f)
settings_ = json.load(f)
resolver_versions = settings_["properties"]["env_data"]["properties"]["resolver_version"]
resolver_versions["default"] = STACK_RESOLVER
return settings_
5 changes: 5 additions & 0 deletions server/autotest_server/testers/haskell/stack_permissions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
echo "allow-different-user: true" >> $STACK_ROOT/config.yaml
echo "recommend-stack-upgrade: false" >> $STACK_ROOT/config.yaml
chmod a+w $STACK_ROOT/stack.sqlite3.pantry-write-lock
chmod a+w $STACK_ROOT/global-project/.stack-work/stack.sqlite3.pantry-write-lock
chmod a+w $STACK_ROOT/pantry/pantry.sqlite3.pantry-write-lock
9 changes: 7 additions & 2 deletions server/autotest_server/testers/r/lib/r_tester_setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ library(remotes)
main <- function() {
# Tester dependencies
# rjson v0.2.20 is required to support R v3.x
deps <- "testthat, rjson (== 0.2.20)"
deps <- "testthat, rjson (== 0.2.20), stringi, tidyverse"

# Additional dependencies for test environment from command-line args
args <- commandArgs(TRUE)
Expand Down Expand Up @@ -53,7 +53,12 @@ install_dep <- function(row) {
} else if (!is.na(version)) {
install_version(name, version = paste(compare, version, sep =" "))
} else {
install.packages(name)
if (name == 'stringi') {
install.packages(name, configure.args="--disable-pkg-config")
}
else {
install.packages(name)
}
}

if (!(name %in% installed.packages())) {
Expand Down
4 changes: 3 additions & 1 deletion server/autotest_server/tests/fixtures/test_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ redis_url: fake_url
supervisor_url: fake_url
workers:
- user: fake_user
queues:
queues: &queues
- high
- low
- batch
- user: fake_user_2
queues: *queues
38 changes: 38 additions & 0 deletions server/autotest_server/tests/test_autotest_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,41 @@ def test_pre_remove():
autotest_server._clear_working_directory(autotest_worker_working_dir, autotest_worker)

assert os.path.exists(path) is False


def test_tmp_remove_file():
workers = autotest_server.config["workers"]
autotest_worker = workers[0]["user"]
autotest_worker_working_dir = f"/home/docker/.autotesting/workers/{autotest_worker}"
path = "/tmp/test.txt"
touch_cmd = f"sudo -u {autotest_worker} touch {path}"
subprocess.run(touch_cmd, shell=True)
autotest_server._clear_working_directory(autotest_worker_working_dir, autotest_worker)
assert os.path.exists(path) is False


def test_tmp_remove_dir():
workers = autotest_server.config["workers"]
autotest_worker = workers[0]["user"]
autotest_worker_working_dir = f"/home/docker/.autotesting/workers/{autotest_worker}"
path = "/tmp/folder"
mkdir_cmd = f"sudo -u {autotest_worker} mkdir {path}"
subprocess.run(mkdir_cmd, shell=True)
touch_cmd = f"sudo -u {autotest_worker} touch {path}/test.txt"
subprocess.run(touch_cmd, shell=True)
autotest_server._clear_working_directory(autotest_worker_working_dir, autotest_worker)
assert os.path.exists(path) is False


def test_tmp_remove_other_user():
workers = autotest_server.config["workers"]
autotest_worker_creator = workers[0]["user"]
autotest_worker_remover = workers[1]["user"]
autotest_worker_working_dir = f"/home/docker/.autotesting/workers/{autotest_worker_remover}"
path = "/tmp/folder"
mkdir_cmd = f"sudo -u {autotest_worker_creator} mkdir {path}"
subprocess.run(mkdir_cmd, shell=True)
touch_cmd = f"sudo -u {autotest_worker_creator} touch {path}/test.txt"
subprocess.run(touch_cmd, shell=True)
autotest_server._clear_working_directory(autotest_worker_working_dir, autotest_worker_remover)
assert os.path.exists(path) is True

0 comments on commit 13f2b63

Please sign in to comment.