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

Use docker-compose to run tests #1221

Merged
merged 19 commits into from
Dec 17, 2022
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.dockerignore
Dockerfile
docker-compose*.yml
.vagrant/
5 changes: 5 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
coverage:
status:
project:
default:
threshold: 1%
77 changes: 12 additions & 65 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,78 +8,25 @@ jobs:
test:
runs-on: ubuntu-20.04

services:
postgres:
image: postgres:12
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- uses: actions/checkout@v2
with:
submodules: true

- uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install dependencies
run: |
sudo apt-get update -y
sudo apt-get install -y \
build-essential \
php7.4-cli \
haskell-platform \
fp-compiler \
python2.7 \
cppreference-doc-en-html \
cgroup-lite \
libcap-dev \
python-dev \
libpq-dev \
libcups2-dev \
libyaml-dev \
rustc \
mono-mcs

- name: Install requirements
- name: Check available cgroups
run: |
# Use distutils from the standard library for 2to3 translation
export SETUPTOOLS_USE_DISTUTILS="stdlib"

pip install -U pip setuptools wheel
pip install -r requirements.txt
pip install -r dev-requirements.txt
mount | grep cgroup

sudo $(which python) prerequisites.py -y --cmsuser=$USER install
python setup.py install

- name: Set up database
env:
PGPASSWORD: postgres
- name: Run tests
run: |
psql --host=localhost --username=postgres --command="CREATE USER cmsuser WITH PASSWORD 'your_password_here';"
docker-compose -f docker-compose.test.yml run cms_test

createdb --host=localhost --username=postgres --owner=cmsuser cmsdb
psql --host=localhost --username=postgres --dbname=cmsdb --command='ALTER SCHEMA public OWNER TO cmsuser'
psql --host=localhost --username=postgres --dbname=cmsdb --command='GRANT SELECT ON pg_largeobject TO cmsuser'

createdb --host=localhost --username=postgres --owner=cmsuser cmsdbfortesting
psql --host=localhost --username=postgres --dbname=cmsdbfortesting --command='ALTER SCHEMA public OWNER TO cmsuser'
psql --host=localhost --username=postgres --dbname=cmsdbfortesting --command='GRANT SELECT ON pg_largeobject TO cmsuser'

cp ./config/cms.conf.sample ./config/cms.conf
sed -e "s/\"cmsuser\": \"cmsuser\"/\"cmsuser\": \"$USER\"/" -i ./config/cms.conf

cmsInitDB
- uses: codecov/codecov-action@v3
with:
files: ./codecov/unittests.xml
flags: unittests

- name: Run tests
run: |
cmsRunTests -v --coverage --codecov
- uses: codecov/codecov-action@v3
with:
files: ./codecov/functionaltests.xml
flags: functionaltests
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*~
.DS_Store
*.mo
.*.sw?
*.pyc
Expand All @@ -11,3 +12,4 @@ cms.egg-info
cache/
lib/
log/
.vagrant/
53 changes: 53 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# syntax=docker/dockerfile:1
FROM ubuntu:20.04

RUN apt-get update
RUN apt-get install -y \
build-essential \
cgroup-lite \
cppreference-doc-en-html \
fp-compiler \
git \
haskell-platform \
libcap-dev \
libcups2-dev \
libffi-dev \
libpq-dev \
libyaml-dev \
mono-mcs \
openjdk-8-jdk-headless \
php7.4-cli \
postgresql-client \
python2 \
python3-pip \
python3.8 \
python3.8-dev \
rustc \
sudo \
wait-for-it \
zip

# Create cmsuser user with sudo privileges
RUN useradd -ms /bin/bash cmsuser && \
usermod -aG sudo cmsuser
# Disable sudo password
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
# Set cmsuser as default user
USER cmsuser

COPY --chown=cmsuser:cmsuser . /home/cmsuser/cms

WORKDIR /home/cmsuser/cms

RUN sudo pip3 install -r requirements.txt
RUN sudo pip3 install -r dev-requirements.txt
RUN sudo python3 setup.py install

RUN sudo python3 prerequisites.py --yes --cmsuser=cmsuser install

RUN sudo sed 's/cmsuser:your_password_here@localhost/postgres@db/' ./config/cms.conf.sample \
| sudo tee /usr/local/etc/cms-testdb.conf

ENV LANG C.UTF-8

CMD [""]
18 changes: 6 additions & 12 deletions cmstestsuite/RunFunctionalTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Copyright © 2013-2018 Stefano Maggiolo <s.maggiolo@gmail.com>
# Copyright © 2014 Luca Versari <veluca93@gmail.com>
# Copyright © 2016 Luca Wehrstedt <luca.wehrstedt@gmail.com>
# Copyright © 2022 William Di Luigi <williamdiluigi@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand All @@ -28,8 +29,7 @@
from cms import utf8_decoder
from cmstestsuite import CONFIG
from cmstestsuite.Tests import ALL_TESTS
from cmstestsuite.coverage import clear_coverage, combine_coverage, \
send_coverage_to_codecov
from cmstestsuite.coverage import clear_coverage, combine_coverage
from cmstestsuite.profiling import \
PROFILER_KERNPROF, PROFILER_NONE, PROFILER_YAPPI
from cmstestsuite.testrunner import TestRunner
Expand Down Expand Up @@ -168,19 +168,16 @@ def main():
parser.add_argument(
"-v", "--verbose", action="count", default=0,
help="print debug information (use multiple times for more)")
parser.add_argument(
"--codecov", action="store_true",
help="send coverage results to Codecov (requires --coverage)")
g = parser.add_mutually_exclusive_group()
g.add_argument(
"--coverage", action="store_true",
help="compute line coverage information")
"--coverage", action="store", type=utf8_decoder,
help="path to the XML coverage report file (if not specified, "
"coverage is not computed)")
g.add_argument(
"--profiler", choices=[PROFILER_YAPPI, PROFILER_KERNPROF],
default=PROFILER_NONE, help="set profiler")

args = parser.parse_args()
if args.codecov and not args.coverage:
parser.error("--codecov requires --coverage")

CONFIG["VERBOSITY"] = args.verbose
CONFIG["COVERAGE"] = args.coverage
Expand Down Expand Up @@ -239,9 +236,6 @@ def main():
runner.log_elapsed_time()
combine_coverage()

if args.codecov:
send_coverage_to_codecov("functionaltests")

logger.info("Executed: %s", tests)
logger.info("Failed: %s", len(failures))
if not failures:
Expand Down
16 changes: 5 additions & 11 deletions cmstestsuite/RunUnitTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Contest Management System - http://cms-dev.github.io/
# Copyright © 2013-2018 Stefano Maggiolo <s.maggiolo@gmail.com>
# Copyright © 2016 Luca Wehrstedt <luca.wehrstedt@gmail.com>
# Copyright © 2022 William Di Luigi <williamdiluigi@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand All @@ -28,7 +29,7 @@
from cms import utf8_decoder
from cmstestsuite import CONFIG, TestException, sh
from cmstestsuite.coverage import clear_coverage, combine_coverage, \
coverage_cmdline, send_coverage_to_codecov
coverage_cmdline
from cmstestsuite.profiling import \
PROFILER_KERNPROF, PROFILER_NONE, PROFILER_YAPPI, profiling_cmdline

Expand Down Expand Up @@ -144,13 +145,11 @@ def main():
"-r", "--retry-failed", action="store_true",
help="only run failed tests from the previous run (stored in %s)" %
FAILED_UNITTEST_FILENAME)
parser.add_argument(
"--codecov", action="store_true",
help="send coverage results to Codecov (requires --coverage)")
g = parser.add_mutually_exclusive_group()
g.add_argument(
"--coverage", action="store_true",
help="compute line coverage information")
"--coverage", action="store", type=utf8_decoder,
help="path to the XML coverage report file (if not specified, "
"coverage is not computed)")
g.add_argument(
"--profiler", choices=[PROFILER_YAPPI, PROFILER_KERNPROF],
default=PROFILER_NONE, help="set profiler")
Expand All @@ -164,8 +163,6 @@ def main():
help="unused")

args = parser.parse_args()
if args.codecov and not args.coverage:
parser.error("--codecov requires --coverage")

CONFIG["VERBOSITY"] = args.verbose
CONFIG["COVERAGE"] = args.coverage
Expand Down Expand Up @@ -227,9 +224,6 @@ def test_match(t):
end_time = datetime.datetime.now()
print("Time elapsed: %s" % (end_time - start_time))

if args.codecov:
send_coverage_to_codecov("unittests")

if passed:
return 0
else:
Expand Down
Loading