Skip to content

Commit

Permalink
Update ctest wrappers for anonymous shared memory and other fixups (#195
Browse files Browse the repository at this point in the history
)

Specifically, fix the dependency logic for ctest fixtures to avoid some periodic
random failures when multiple optimizers tried to start at once (colliding on
the use of the port) and remove unnecessary dependencies (Mlos.UnitTest didn't
need any of the optimizer fixtures).
  • Loading branch information
bpkroth authored Dec 1, 2020
1 parent e3904dd commit dd4d428
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 109 deletions.
24 changes: 0 additions & 24 deletions build/CMakeHelpers/CheckForMlosSharedMemories.sh

This file was deleted.

17 changes: 0 additions & 17 deletions build/CMakeHelpers/RemoveMlosSharedMemories.sh

This file was deleted.

21 changes: 0 additions & 21 deletions build/CMakeHelpers/RunTestsAndSharedMemChecks.sh

This file was deleted.

72 changes: 25 additions & 47 deletions build/Mlos.Cpp.UnitTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,6 @@ if(NOT googletest_POPULATED)
endif()


# Add some test fixtures to use for setup/tear down of other Mlos unit tests.

# Note: Fixtures only run once per ctest invokation.
# That's fine for the pre-check, but the cleanup step, so we moved that into
# the test command itself for now.

# These "tests" are really just to help define fixtures to be depended on by
# other tests for setup/tear down checks.
add_test(NAME CheckForMlosSharedMemories
COMMAND ${MLOS_ROOT}/build/CMakeHelpers/CheckForMlosSharedMemories.sh)
#add_test(NAME RemoveMlosSharedMemories
# COMMAND ${MLOS_ROOT}/build/CMakeHelpers/RemoveMlosSharedMemories.sh)
# These properties add the pre/post actions for the "MlosSharedMemoriesChecks" fixture.
set_tests_properties(CheckForMlosSharedMemories PROPERTIES
FIXTURES_SETUP MlosSharedMemoriesChecks)
#set_tests_properties(RemoveMlosSharedMemories PROPERTIES
# FIXTURES_CLEANUP MlosSharedMemoriesChecks)
# Now other test can add "MlosSharedMemoriesChecks" to their
# "FIXTURES_REQUIRED" property to invoke these scripts before/after themselves.
add_test(NAME LocalPipInstallMlos
COMMAND ${PYTHON3} -m pip install -e ${MLOS_ROOT}/source/Mlos.Python)
add_test(NAME StartMlosOptimizerService
COMMAND ${MLOS_ROOT}/build/CMakeHelpers/BackgroundProcessHelper.sh
start /tmp/mlos_optimizer_microservice.pid /tmp/mlos_optimizer_microservice.log
${PYTHON3} ${MLOS_ROOT}/source/Mlos.Python/mlos/start_optimizer_microservice.py launch --port 54321)
add_test(NAME StopMlosOptimizerService
COMMAND ${MLOS_ROOT}/build/CMakeHelpers/BackgroundProcessHelper.sh
stop /tmp/mlos_optimizer_microservice.pid /tmp/mlos_optimizer_microservice.log)
set_tests_properties(StartMlosOptimizerService PROPERTIES
DEPENDS LocalPipInstallMlos
FIXTURES_SETUP MlosOptimizerService)
set_tests_properties(StopMlosOptimizerService PROPERTIES
FIXTURES_CLEANUP MlosOptimizerService)

# Mark all setup/tear down activities involving the shared memory regions as
# mutually exclusive (no parallel runs).
set_tests_properties(
CheckForMlosSharedMemories
#RemoveMlosSharedMemories
PROPERTIES RESOURCE_LOCK MlosSharedMemories)

# add_mlos_agent_server_exe_test_run()
#
# Provide a function for handling some of the boilerplate to setup a test run
Expand Down Expand Up @@ -116,23 +75,42 @@ function(add_mlos_agent_server_exe_test_run)
# - Make sure that the Agent can find the SettingsRegistry DLLs that the
# /some/test/exe needs to use.
add_test(NAME ${TEST_NAME}
COMMAND ${MLOS_ROOT}/build/CMakeHelpers/RunTestsAndSharedMemChecks.sh
${DOTNET} $<TARGET_PROPERTY:Mlos.Agent.Server,DOTNET_OUTPUT_DLL>
COMMAND ${DOTNET} $<TARGET_PROPERTY:Mlos.Agent.Server,DOTNET_OUTPUT_DLL>
--executable $<TARGET_FILE:${TEST_EXECUTABLE_TARGET}>
--settings-registry-path "${SETTINGS_REGISTRY_PATH}"
${EXPERIMENT_SESSION_ARGS}
${OPTIMIZER_ARGS})
set_tests_properties(${TEST_NAME} PROPERTIES
TIMEOUT ${TEST_TIMEOUT}
# Make sure to check for existing shared registry memories before hand.
FIXTURES_REQUIRED MlosSharedMemoriesChecks
# This test conflicts with any other test using the MlosSharedMemories
# (no parallel test runs).
# (no parallel test runs for the moment).
RESOURCE_LOCK MlosSharedMemories)
if(${WITH_OPTIMIZER})
# Add some test fixtures to use for setup/tear down of other Mlos unit tests.
#
add_test(NAME LocalPipInstallMlos
COMMAND ${PYTHON3} -m pip install -q -e ${MLOS_ROOT}/source/Mlos.Python)
add_test(NAME StartMlosOptimizerService
COMMAND ${MLOS_ROOT}/build/CMakeHelpers/BackgroundProcessHelper.sh
start /tmp/mlos_optimizer_microservice.pid /tmp/mlos_optimizer_microservice.log
${PYTHON3} ${MLOS_ROOT}/source/Mlos.Python/mlos/start_optimizer_microservice.py launch --port 54321)
add_test(NAME StopMlosOptimizerService
COMMAND ${MLOS_ROOT}/build/CMakeHelpers/BackgroundProcessHelper.sh
stop /tmp/mlos_optimizer_microservice.pid /tmp/mlos_optimizer_microservice.log)
set_tests_properties(StartMlosOptimizerService PROPERTIES
DEPENDS LocalPipInstallMlos
FIXTURES_SETUP MlosOptimizerService
RESOURCE_LOCK MlosOptimizerServicePort)
set_tests_properties(StopMlosOptimizerService PROPERTIES
FIXTURES_CLEANUP MlosOptimizerService)

get_test_property(${TEST_NAME} RESOURCE_LOCK TEST_RESOURCE_LOCKS)
get_test_property(${TEST_NAME} FIXTURES_REQUIRED TEST_FIXTURES_REQUIRED)
set_tests_properties(${TEST_NAME} PROPERTIES
FIXTURES_REQUIRED MlosOptimizerService)
FIXTURES_REQUIRED "MlosOptimizerService;${TEST_FIXTURES_REQUIRED}"
RESOURCE_LOCK "MlosOptimizerServicePort;${TEST_RESOURCE_LOCKS}")
endif()

# Include these targets in cmake's "check" target so we can build/test in one shot.
add_dependencies(check ${TEST_EXECUTABLE_TARGET} Mlos.Agent.Server)
add_dependencies(${TEST_EXECUTABLE_TARGET} Mlos.Agent.Server)
Expand Down

0 comments on commit dd4d428

Please sign in to comment.