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

Add isolated gmock test #4

Merged
merged 7 commits into from
Jun 13, 2019
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
7 changes: 7 additions & 0 deletions ament_cmake_ros/ament_cmake_ros-extras.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,12 @@

# generated from ament_cmake_ros/ament_cmake_ros-extras.cmake.in

find_package(ament_cmake_gmock QUIET REQUIRED)
find_package(ament_cmake_gtest QUIET REQUIRED)
find_package(ament_cmake_pytest QUIET REQUIRED)
include("${ament_cmake_ros_DIR}/ament_add_ros_isolated_gmock.cmake")
include("${ament_cmake_ros_DIR}/ament_add_ros_isolated_gtest.cmake")
include("${ament_cmake_ros_DIR}/ament_add_ros_isolated_pytest.cmake")

include("${ament_cmake_ros_DIR}/build_shared_libs.cmake")
add_definitions(-DROS_PACKAGE_NAME=\"${PROJECT_NAME}\")
39 changes: 39 additions & 0 deletions ament_cmake_ros/cmake/ament_add_ros_isolated_gmock.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2019 Apex.AI, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#
# Add a gmock test that runs with ROS_DOMAIN_ID isolation.
# If no ROS_DOMAIN_ID is set, automatically select one not in use by another
# isolated test before running the target test.
# This will prevent tests running in parallel from interfering with
# one-another.
#
# This behavior can be disabled for debugging in two ways:
# 1) Creating an environment variable called DISABLE_ROS_ISOLATION
# 2) Setting a ROS_DOMAIN_ID environment variable.
# This will cause the tests to use that ROS_DOMAIN_ID.
#
# Parameters are the same as ament_add_gmock

function(ament_add_ros_isolated_gmock target)

set(RUNNER "RUNNER" "${ament_cmake_ros_DIR}/run_test_isolated.py")

ament_add_gmock(
"${target}"
RUNNER "${RUNNER}"
${ARGN}
)

endfunction()
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@

#
# Add a gtest that runs with ROS_DOMAIN_ID isolation.
# If no ROS_DOMAIN_ID is set, automatically select one not in use by another isolated test
# before running the target test.
# This will prevent tests running in parallel from interfering with one-another.
# If no ROS_DOMAIN_ID is set, automatically select one not in use by another
# isolated test before running the target test.
# This will prevent tests running in parallel from interfering with
# one-another.
#
# This behavior can be disabled for debugging in two ways:
# 1) Creating an environment variable called DISABLE_ROS_ISOLATION
# 1) Creating an environment variable called DISABLE_ROS_ISOLATION
# 2) Setting a ROS_DOMAIN_ID environment variable.
# This will cause the tests to use that ROS_DOMAIN_ID.
#
# Parameters are the same as ament_add_gtest

function(ament_add_ros_isolated_gtest target)

set(RUNNER "RUNNER" "${ament_cmake_ros_isolated_test_DIR}/run_test_isolated.py")
set(RUNNER "RUNNER" "${ament_cmake_ros_DIR}/run_test_isolated.py")

ament_add_gtest(
"${target}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@

#
# Add a pytest that runs with ROS_DOMAIN_ID isolation.
# If no ROS_DOMAIN_ID is set, automatically select one not in use by another isolated test
# before running the target test.
# This will prevent tests running in parallel from interfering with one-another.
# If no ROS_DOMAIN_ID is set, automatically select one not in use by another
# isolated test before running the target test.
# This will prevent tests running in parallel from interfering with
# one-another.
#
# This behavior can be disabled for debugging in two ways:
# 1) Creating an environment variable called DISABLE_ROS_ISOLATION
# 1) Creating an environment variable called DISABLE_ROS_ISOLATION
# 2) Setting a ROS_DOMAIN_ID environment variable.
# This will cause the tests to use that ROS_DOMAIN_ID.
#
# Parameters are the same as ament_add_pytest_test

function(ament_add_ros_isolated_pytest_test testname path)

set(RUNNER "${ament_cmake_ros_isolated_test_DIR}/run_test_isolated.py")
set(RUNNER "${ament_cmake_ros_DIR}/run_test_isolated.py")

ament_add_pytest_test(
"${testname}" "${path}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
import os
import sys

import ament_cmake_test
import domain_coordinator
Expand Down
4 changes: 4 additions & 0 deletions ament_cmake_ros/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
<license>Apache License 2.0</license>

<buildtool_depend>ament_cmake</buildtool_depend>
<depend>domain_coordinator</depend>

<buildtool_export_depend>ament_cmake</buildtool_export_depend>
<buildtool_export_depend>ament_cmake_gtest</buildtool_export_depend>
<buildtool_export_depend>ament_cmake_gmock</buildtool_export_depend>
<buildtool_export_depend>ament_cmake_pytest</buildtool_export_depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
Expand Down
14 changes: 0 additions & 14 deletions ament_cmake_ros_isolated_gtest/CMakeLists.txt

This file was deleted.

This file was deleted.

19 changes: 0 additions & 19 deletions ament_cmake_ros_isolated_gtest/package.xml

This file was deleted.

14 changes: 0 additions & 14 deletions ament_cmake_ros_isolated_pytest/CMakeLists.txt

This file was deleted.

This file was deleted.

19 changes: 0 additions & 19 deletions ament_cmake_ros_isolated_pytest/package.xml

This file was deleted.

12 changes: 0 additions & 12 deletions ament_cmake_ros_isolated_test/CMakeLists.txt

This file was deleted.

17 changes: 0 additions & 17 deletions ament_cmake_ros_isolated_test/package.xml

This file was deleted.

8 changes: 8 additions & 0 deletions domain_coordinator/test/test_domain_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@

class TestUniqueness(unittest.TestCase):

@classmethod
def setUpClass(cls):
# If a ros_isolated test (that uses the domain coordinator) runs at the same time as the
# domain_coordinator test, then the domain_coordinator tests may fail.
# When we're self-testing the domain_coordinator, select a different PORT_BASE so the
# the ports used by the test are different than the ports used for real
domain_coordinator._PORT_BASE += 100

def test_quickly(self):
"""
Quick test with false negatives, but simple and easy to understand.
Expand Down