Skip to content

CXX-3294 Relocate all remaining Manual Doc Page examples into the examples directory #1407

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

Merged
merged 9 commits into from
May 21, 2025

Conversation

eramongodb
Copy link
Contributor

@eramongodb eramongodb commented May 21, 2025

Resolves CXX-3294. Followup to #1403, which broke downstream Manual Doc pages due to several example code blocks that still remained under the test directory (these are identified by // (Start|Begin|End) <name> comments). All such remaining code blocks are copied into equivalent files under the examples/mongocxx/mongodb.com directory for consistency and to inform future maintainers about their stability requirement by downstream Manual Doc pages. Although the comments under the test directory are removed, the code itself remains to preserve code coverage as part of the test suite.

Catch2 assertions such as CHECK(cond) are converted into if (!cond) { throw std::logic_error{...}; } for consistency with other example code. The rest of the code block contents and structure is otherwise preserved as much as possible with their prior form as SECTION() blocks.

As a drive-by fix/improvement, the requirement that the replica set against which the examples are run is named repl0 (with replicaSet=repl0) is removed. AFAIK no such expectation or requirement is necessary for example code.

@eramongodb eramongodb requested a review from kevinAlbs May 21, 2025 16:49
@eramongodb eramongodb self-assigned this May 21, 2025
@eramongodb eramongodb requested a review from a team as a code owner May 21, 2025 16:49
@@ -457,20 +457,17 @@ TEST_CASE("Documentation Examples", "[change_stream]") {
}};

SECTION("Example 1") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code itself remains to preserve code coverage as part of the test suite.

Suggest removing the doc examples from tests to avoid going out-of-sync. I expect the main purpose is documentation rather than testing. And the examples are run on most Evergreen configurations.

Copy link
Collaborator

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with minor suggestions.

Comment on lines 182 to 184
mongocxx::client const conn{mongocxx::uri{}};

auto const db = conn["documentation_examples"];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mongocxx::client const conn{mongocxx::uri{}};
auto const db = conn["documentation_examples"];

Unused.

Comment on lines 179 to 180
for (auto const& example : examples) {
mongocxx::pool pool{mongocxx::uri{}};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (auto const& example : examples) {
mongocxx::pool pool{mongocxx::uri{}};
mongocxx::pool pool{mongocxx::uri{}};
for (auto const& example : examples) {

Suggest creating pool outside of loop. Pool destruction signals and waits for monitoring threads to shut down. Timing cmake --build cmake-build --target run-examples-mongocxx-mongodb.com-change_streams_examples locally showed a decrease of 2.207s => 1.156s.

@eramongodb eramongodb merged commit 073e696 into mongodb:master May 21, 2025
9 of 10 checks passed
@eramongodb eramongodb deleted the cxx-examples branch May 21, 2025 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants