Skip to content

Commit

Permalink
Parallel tests (#1786)
Browse files Browse the repository at this point in the history
* [DEV] Add parallel option in tests

* [DEV] Add parallel tests for short tests

* [FIX] Use store_true

* [DEV] Use nproc for ubuntu centos oracle

* [DEV] Use force-parallel

* [DEV] Change batch name to valid-parallel

* [DEV] Add to windows CI, fix thread num to 2

* [DEV] Add case tests to simple study

* [DEV] Move parallel tests first

* [DEV] Move parallel tests back

* [FIX] named mps
  • Loading branch information
payetvin authored Dec 6, 2023
1 parent 656152d commit 4475590
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/centos7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
run: |
source /opt/rh/devtoolset-9/enable
source /opt/rh/rh-git227/enable
cmake3 --build _build --config Release -j2
cmake3 --build _build --config Release -j$(nproc)
ccache -s
- name: Installer .rpm creation
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/oracle8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
- name: Build
run: |
source /opt/rh/gcc-toolset-9/enable
cmake --build _build --config Release -j2
cmake --build _build --config Release -j$(nproc)
- name: Run unit and end-to-end tests
if: ${{ env.IS_PUSH == 'true' }}
Expand Down
12 changes: 11 additions & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
- name: Build
run: |
cmake --build _build --config release -j2
cmake --build _build --config release -j$(nproc)
# simtest
Expand All @@ -114,6 +114,7 @@ jobs:
path: 'simtest.json'
prop_path: 'version'


- name: Run named mps tests
if: ${{ env.IS_PUSH == 'true' }}
uses: ./.github/workflows/run-tests
Expand Down Expand Up @@ -174,6 +175,15 @@ jobs:
batch-name: valid-v870
os: ${{ matrix.test-platform }}

- name: Run parallel tests
if: ${{ env.IS_PUSH == 'true' }}
uses: ./.github/workflows/run-tests
with:
simtest-tag: ${{steps.simtest-version.outputs.prop}}
batch-name: valid-parallel
os: ${{ matrix.test-platform }}
variant: "parallel"

- name: Run short-tests
if: ${{ env.IS_PUSH == 'true' }}
uses: ./.github/workflows/run-tests
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/windows-vcpkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ jobs:
batch-name: valid-v870
os: ${{ matrix.test-platform }}

- name: Run parallel tests
if: ${{ env.IS_PUSH == 'true' }}
uses: ./.github/workflows/run-tests
with:
simtest-tag: ${{steps.simtest-version.outputs.prop}}
batch-name: valid-parallel
os: ${{ matrix.test-platform }}
variant: "parallel"

- name: Run short-tests
uses: ./.github/workflows/run-tests
with:
Expand Down
6 changes: 6 additions & 0 deletions src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ if(Python3_Interpreter_FOUND)
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/run-study-tests"
)

add_test(
NAME parallel
COMMAND Python3::Interpreter -m pytest -m json --solver-path=$<TARGET_FILE:antares-solver> --force-parallel
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/run-study-tests"
)

# The Kirchhoff constraint builder is built only if BUILD_TOOLS=ON
if (BUILD_TOOLS)
add_test(
Expand Down
35 changes: 35 additions & 0 deletions src/tests/end-to-end/simple_study/simple-study.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,41 @@ BOOST_AUTO_TEST_CASE(milp_two_mc_two_unit_single_scenario)
tt::tolerance(0.001));
BOOST_TEST(output.thermalNbUnitsON(cluster.get()).hour(10) == 2, tt::tolerance(0.001));
}

BOOST_AUTO_TEST_CASE(parallel)
{
setNumberMCyears(10);
study->maxNbYearsInParallel = 2;

simulation->create();
simulation->run();

OutputRetriever output(simulation->rawSimu());
BOOST_TEST(output.overallCost(area).hour(0) == loadInArea * clusterCost, tt::tolerance(0.001));
BOOST_TEST(output.load(area).hour(0) == loadInArea, tt::tolerance(0.001));
}

BOOST_AUTO_TEST_CASE(parallel2)
{
setNumberMCyears(2);
study->maxNbYearsInParallel = 2;

loadTSconfig.setColumnCount(2)
.fillColumnWith(0, 7.0)
.fillColumnWith(1, 7.0);

clusterConfig.setAvailablePowerNumberOfTS(2)
.setAvailablePower(0, 50.)
.setAvailablePower(1, 50.);

simulation->create();
simulation->run();

OutputRetriever output(simulation->rawSimu());
BOOST_TEST(output.overallCost(area).hour(0) == loadInArea * clusterCost, tt::tolerance(0.001));
BOOST_TEST(output.load(area).hour(0) == loadInArea, tt::tolerance(0.001));
}

BOOST_AUTO_TEST_SUITE_END()


Expand Down
6 changes: 5 additions & 1 deletion src/tests/run-study-tests/actions_on_study/study_run.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import subprocess
import os
from pathlib import Path
from utils.assertions import check

class study_run:
def __init__(self, study_path, solver_path, use_ortools, ortools_solver, named_mps_problems):
def __init__(self, study_path, solver_path, use_ortools, ortools_solver, named_mps_problems, parallel):
self.study_path = study_path
self.solver_path = solver_path
self.use_ortools = use_ortools
self.ortools_solver = ortools_solver
self.named_mps_problems = named_mps_problems
self.parallel = parallel
self.raise_exception_on_failure = True
self.return_code = 0

Expand All @@ -26,6 +28,8 @@ def run(self):
command.append('--ortools-solver=' + self.ortools_solver)
if self.named_mps_problems:
command.append('--named-mps-problems')
if self.parallel:
command.append('--force-parallel=2')
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
process.communicate()

Expand Down
9 changes: 7 additions & 2 deletions src/tests/run-study-tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def pytest_addoption(parser):
parser.addoption("--ortools-solver", action="store", default="sirius")
parser.addoption("--solver-path", action="store")
parser.addoption("--named-mps-problems", action="store_true", default=False)
parser.addoption("--force-parallel", action="store_true", default=False)

@pytest.fixture()
def ortools_solver(request):
Expand All @@ -13,11 +14,15 @@ def ortools_solver(request):
@pytest.fixture()
def use_ortools(request):
return request.config.getoption("--use-ortools")

@pytest.fixture()
def solver_path(request):
return request.config.getoption("--solver-path")

@pytest.fixture()
def named_mps_problems(request):
return request.config.getoption("--named-mps-problems")

@pytest.fixture()
def parallel(request):
return request.config.getoption("--force-parallel")
4 changes: 2 additions & 2 deletions src/tests/run-study-tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def resultsRemover(study_path):
return results_remover(study_path)

@pytest.fixture
def simulation(study_path, solver_path, use_ortools, ortools_solver, named_mps_problems):
return study_run(study_path, solver_path, use_ortools, ortools_solver, named_mps_problems)
def simulation(study_path, solver_path, use_ortools, ortools_solver, named_mps_problems, parallel):
return study_run(study_path, solver_path, use_ortools, ortools_solver, named_mps_problems, parallel)

@pytest.fixture(autouse=True)
def check_runner(simulation, resultsRemover):
Expand Down

0 comments on commit 4475590

Please sign in to comment.