Skip to content

Commit 7918494

Browse files
authored
CXX-1201 Support running examples against various topologies (#1190)
* Remove examples/projects/CMakeLists.txt * Remove obsolete file(GLOB) for Markdown files under examples * Add examples/add_subdirectory to dist files * Add MONGOCXX_TEST_TOPOLOGY to EVG config * Replace add_subdirectory() with file(GLOB_RECURSE) for existing examples * Replace POST_BUILD COMMAND with run-example-* targets * CXX-1201 unskip building examples/mongocxx/change_streams.cpp * CXX-1201 unskip examples/mongocxx/client_session.cpp * CXX-1201 unskip examples/mongocxx/with_transaction.cpp * CXX-1201 unskip examples/mongocxx/causal_consistency.cpp * CXX-1201 unskip building mongocxx encryption examples * Match replicaSet URI option with mongo orchestration config * Emit example output to stdout * Disable printing of error messages on Evergreen due to MSBuild * Disable implicit build dependency on executable targets * Add file(GLOB_RECURSE) for API examples * Avoid compiling fwd.hpp headers * Add support for Markdown API docs
1 parent 54b0cac commit 7918494

File tree

17 files changed

+259
-285
lines changed

17 files changed

+259
-285
lines changed

.evergreen/test.sh

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ set -o pipefail
1212
: "${cse_gcp_email:?}"
1313
: "${cse_gcp_privatekey:?}"
1414
: "${distro_id:?}" # Required by find-cmake-latest.sh.
15+
: "${MONGOCXX_TEST_TOPOLOGY:?}"
1516

1617
: "${CRYPT_SHARED_LIB_PATH:-}"
1718
: "${disable_slow_tests:-}"
@@ -224,15 +225,20 @@ fi
224225
pushd "${working_dir:?}/build"
225226

226227
if [[ "${OSTYPE:?}" =~ cygwin ]]; then
227-
CTEST_OUTPUT_ON_FAILURE=1 "${cmake_binary:?}" --build . --target RUN_TESTS -- /p:Configuration="${build_type:?}" /verbosity:minimal
228+
CTEST_OUTPUT_ON_FAILURE=1 "${cmake_binary:?}" --build . --config "${build_type:?}" --target RUN_TESTS -- /verbosity:minimal
229+
230+
echo "Building examples..."
231+
"${cmake_binary:?}" --build . --config "${build_type:?}" --target examples/examples
232+
echo "Building examples... done."
233+
228234
# Only run examples if MONGODB_API_VERSION is unset. We do not append
229235
# API version to example clients, so examples will fail when requireApiVersion
230236
# is true.
231237
if [[ -z "$MONGODB_API_VERSION" ]]; then
232238
echo "Running examples..."
233-
if ! CTEST_OUTPUT_ON_FAILURE=1 "${cmake_binary:?}" --build . --target examples/run-examples -- /p:Configuration="${build_type:?}" /verbosity:minimal >|output.txt 2>&1; then
239+
if ! "${cmake_binary:?}" --build . --config "${build_type:?}" --target examples/run-examples --parallel 1 -- /verbosity:minimal >|output.txt 2>&1; then
234240
# Only emit output on failure.
235-
cat output.txt 1>&2
241+
cat output.txt
236242
exit 1
237243
fi
238244
echo "Running examples... done."
@@ -278,42 +284,21 @@ else
278284
run_test ./src/mongocxx/test/test_read_write_concern_specs
279285
run_test ./src/mongocxx/test/test_unified_format_spec
280286

281-
# Some platforms like OS X don't support the /mode syntax to the -perm option
282-
# of find(1), and some platforms like Ubuntu 16.04 don't support the +mode
283-
# syntax, so we use Perl to help us find executable files.
284-
EXAMPLES="$(find examples -type f | sort | perl -nlwe 'print if -x')"
287+
echo "Building examples..."
288+
"${cmake_binary:?}" --build . --target examples
289+
echo "Building examples... done."
285290

286291
# Only run examples if MONGODB_API_VERSION is unset. We do not append
287292
# API version to example clients, so examples will fail when requireApiVersion
288293
# is true.
289294
if [[ -z "${MONGODB_API_VERSION:-}" ]]; then
290-
for test in ${EXAMPLES:?}; do
291-
echo "Running ${test:?}"
292-
case "${test:?}" in
293-
*encryption*)
294-
echo " - Skipping client side encryption example"
295-
;;
296-
*change_stream*)
297-
echo " - TODO CXX-1201, enable for servers that support change streams"
298-
;;
299-
*client_session*)
300-
echo " - TODO CXX-1201, enable for servers that support change streams"
301-
;;
302-
*with_transaction*)
303-
echo " - TODO CXX-1201, enable for servers that support transactions"
304-
;;
305-
*causal_consistency*)
306-
echo " - TODO CXX-1201, enable for servers that support transactions"
307-
;;
308-
*)
309-
if ! run_test "${test:?}" >|output.txt 2>&1; then
310-
# Only emit output on failure.
311-
cat output.txt 1>&2
312-
exit 1
313-
fi
314-
;;
315-
esac
316-
done
295+
echo "Running examples..."
296+
if ! "${cmake_binary:?}" --build . --target run-examples --parallel 1 >|output.txt 2>&1; then
297+
# Only emit output on failure.
298+
cat output.txt
299+
exit 1
300+
fi
301+
echo "Running examples... done."
317302
fi
318303
fi
319304

.mci.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ functions:
512512
- example_projects_ldflags
513513
- generator
514514
- lib_dir
515+
- MONGOCXX_TEST_TOPOLOGY
515516
- MONGODB_API_VERSION
516517
- platform
517518
- TEST_WITH_ASAN
@@ -789,6 +790,8 @@ tasks:
789790
# Call "install_c_driver" before "test" to build static C driver libraries. Example projects require static C driver libraries.
790791
- func: "install_c_driver"
791792
- func: "test"
793+
vars:
794+
MONGOCXX_TEST_TOPOLOGY: single
792795

793796
- name: compile_and_test_with_shared_libs_extra_alignment
794797
commands:
@@ -804,6 +807,8 @@ tasks:
804807
vars:
805808
BSON_EXTRA_ALIGNMENT: 1
806809
- func: "test"
810+
vars:
811+
MONGOCXX_TEST_TOPOLOGY: single
807812

808813
- name: compile_and_test_with_shared_libs_cxx20
809814
commands:
@@ -819,8 +824,9 @@ tasks:
819824
- func: "install_c_driver"
820825
- func: "test"
821826
vars:
822-
REQUIRED_CXX_STANDARD: 20
823827
example_projects_cxx_standard: 20
828+
MONGOCXX_TEST_TOPOLOGY: single
829+
REQUIRED_CXX_STANDARD: 20
824830

825831
- name: compile_and_test_with_shared_libs_extra_alignment_cxx20
826832
commands:
@@ -839,8 +845,9 @@ tasks:
839845
BSON_EXTRA_ALIGNMENT: 1
840846
- func: "test"
841847
vars:
842-
REQUIRED_CXX_STANDARD: 20
843848
example_projects_cxx_standard: 20
849+
MONGOCXX_TEST_TOPOLOGY: single
850+
REQUIRED_CXX_STANDARD: 20
844851

845852
- name: compile_with_shared_libs
846853
commands:
@@ -897,6 +904,7 @@ tasks:
897904
- func: "install_c_driver"
898905
- func: "test"
899906
vars:
907+
MONGOCXX_TEST_TOPOLOGY: single
900908
USE_STATIC_LIBS: 1
901909

902910
- name: compile_and_test_with_static_libs_extra_alignment
@@ -916,6 +924,7 @@ tasks:
916924
BSON_EXTRA_ALIGNMENT: 1
917925
- func: "test"
918926
vars:
927+
MONGOCXX_TEST_TOPOLOGY: single
919928
USE_STATIC_LIBS: 1
920929

921930
- name: compile_and_test_with_shared_libs_replica_set
@@ -932,6 +941,8 @@ tasks:
932941
- func: "run_kms_servers"
933942
- func: "install_c_driver"
934943
- func: "test"
944+
vars:
945+
MONGOCXX_TEST_TOPOLOGY: replica
935946

936947
- name: compile_and_test_with_shared_libs_sharded_cluster
937948
commands:
@@ -947,6 +958,8 @@ tasks:
947958
- func: "run_kms_servers"
948959
- func: "install_c_driver"
949960
- func: "test"
961+
vars:
962+
MONGOCXX_TEST_TOPOLOGY: sharded
950963

951964
# Auto downloading the C driver in the C++ build does not currently include
952965
# support for libmongocrypt, therefore it is not configured with
@@ -965,6 +978,8 @@ tasks:
965978
- func: "clone_drivers-evergreen-tools"
966979
- func: "run_kms_servers"
967980
- func: "test"
981+
vars:
982+
MONGOCXX_TEST_TOPOLOGY: replica
968983

969984
- name: compile_and_test_with_shared_libs_sharded_cluster_with_libmongocrypt
970985
commands:
@@ -979,6 +994,8 @@ tasks:
979994
- func: "clone_drivers-evergreen-tools"
980995
- func: "run_kms_servers"
981996
- func: "test"
997+
vars:
998+
MONGOCXX_TEST_TOPOLOGY: sharded
982999

9831000
- name: uninstall_check
9841001
commands:
@@ -1141,6 +1158,7 @@ tasks:
11411158
- func: "run_kms_servers"
11421159
- func: "test"
11431160
vars:
1161+
MONGOCXX_TEST_TOPOLOGY: single
11441162
MONGODB_API_VERSION: 1
11451163

11461164
- name: test_versioned_api_accept_version_two
@@ -1155,6 +1173,8 @@ tasks:
11551173
- func: "clone_drivers-evergreen-tools"
11561174
- func: "run_kms_servers"
11571175
- func: "test"
1176+
vars:
1177+
MONGOCXX_TEST_TOPOLOGY: single
11581178

11591179
- name: docker_build_arm
11601180
run_on:

Doxyfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,8 @@ EXCLUDE_SYMBOLS = bsoncxx::detail \
10311031
# that contain example code fragments that are included (see the \include
10321032
# command).
10331033

1034-
EXAMPLE_PATH = examples
1034+
EXAMPLE_PATH = docs \
1035+
examples
10351036

10361037
# If the value of the EXAMPLE_PATH tag contains directories, you can use the
10371038
# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and

docs/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
add_subdirectory (themes)
1616

17-
file (GLOB_RECURSE docs_DIST_mds RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} content/*.md)
17+
file (GLOB_RECURSE docs_DIST_mds RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} api/*.md content/*.md)
1818
file (GLOB docs_DIST_htmls RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} layouts/shortcodes/*.html)
1919
file (GLOB docs_DIST_tomls RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.toml data/*.toml)
2020

0 commit comments

Comments
 (0)