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

doc: document Start and Await methods and mocks #14375

Merged
merged 7 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ breaking changes in the upcoming 3.x release. This release is scheduled for

## v2.26.0 - TBD

### BREAKING TESTING CHANGES
Copy link
Member

Choose a reason for hiding this comment

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

nit: doesn't matter, but line break?

If you don't have tests that `EXPECT_CALL` on methods in `MockConnection` that
Copy link
Member

Choose a reason for hiding this comment

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

FTR, ON_CALL would be ambiguous too. Maybe:

If you don't mock Long Running Operations (LRO) in your tests, these changes will not affect you.

perform Long Running Operations (LRO), these changes will not affect you.

With the addition of new methods to support starting Long Running Operations
(LRO) synchronously and awaiting their completion separately, the overload set
for the preexisting LRO methods have been expanded. Uses of `EXPECT_CALL` that
do not have matchers for the arguments will be ambiguous. To quickly remedy this
change instances of `EXPECT_CALL(*mock, Method)` to
`EXPECT_CALL(*mock, Method(_))`.
Copy link
Member

Choose a reason for hiding this comment

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

optional: we wouldn't write this, but maybe s/Method(_)/Method(::testing::_)/ for those who are not familiar with the placeholder.


### New Libraries

We are happy to announce the following GA libraries. Unless specifically noted,
Expand Down
3 changes: 3 additions & 0 deletions generator/internal/client_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ R"""( std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc<
// clang-format on
{method_string},
{"\n"},
{FormatStartMethodComments()},
{IsResponseTypeEmpty,
// clang-format off
" Status\n",
Expand Down Expand Up @@ -267,6 +268,7 @@ R"""( std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc<
" future<StatusOr<$longrunning_deduced_response_type$>>\n"},
{" $method_name$($request_type$ const& request, Options opts = {});\n"},
{"\n"},
{FormatStartMethodComments()},
// clang-format on
{IsResponseTypeEmpty,
// clang-format off
Expand All @@ -276,6 +278,7 @@ R"""( std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc<
"NoAwaitTag, "
"$request_type$ const& request, Options opts = {});\n\n"},
// clang-format on
{FormatAwaitMethodComments()},
{IsResponseTypeEmpty,
// clang-format off
" future<Status>\n",
Expand Down
28 changes: 28 additions & 0 deletions generator/internal/format_method_comments.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,34 @@ bool CheckMethodCommentSubstitutions() {
return all_substitutions_used;
}

std::string FormatStartMethodComments() {
return R"""( // clang-format off
///
/// @copydoc $method_name$
///
/// Specifying the [`NoAwaitTag`] immediately returns the
/// [`$longrunning_operation_type$`] that corresponds to the Long Running
/// Operation that has been started. No polling for operation status occurs.
///
/// [`NoAwaitTag`]: @ref google::cloud::NoAwaitTag
///
// clang-format on
)""";
}

std::string FormatAwaitMethodComments() {
return R"""( // clang-format off
///
/// @copydoc $method_name$
///
/// This method accepts a `$longrunning_operation_type$` that corresponds
/// to a previously started Long Running Operation (LRO) and polls the status
/// of the LRO in the background.
///
// clang-format on
)""";
}

} // namespace generator_internal
} // namespace cloud
} // namespace google
10 changes: 10 additions & 0 deletions generator/internal/format_method_comments.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ std::string FormatMethodComments(
*/
bool CheckMethodCommentSubstitutions();

/**
* Comments for LRO Start overload.
Copy link
Member

Choose a reason for hiding this comment

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

nit: extra space

*/
std::string FormatStartMethodComments();

/**
* Comments for LRO Await overload.
*/
std::string FormatAwaitMethodComments();

} // namespace generator_internal
} // namespace cloud
} // namespace google
Expand Down
9 changes: 7 additions & 2 deletions generator/internal/mock_connection_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,15 @@ class $mock_connection_class_name$ : public $product_namespace$::$connection_cla
Not(IsPaginated))),
MethodPattern(
{
{// clang-format off
"\n // Due to additional overloads for this method\n"
" // EXPECT_CALL(*mock, $method_name$) is now ambiguous. Use\n"
" // EXPECT_CALL(*mock, $method_name$(_)) instead.\n"},
Copy link
Member

Choose a reason for hiding this comment

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

We should use doxygen style comments /// and put the code in code quotes.

And optionally, spell out ::testing::_.

// clang-format on
{IsResponseTypeEmpty,
// clang-format off
"\n MOCK_METHOD(future<Status>,\n",
"\n MOCK_METHOD(future<StatusOr<$longrunning_deduced_response_type$>>,\n"},
" MOCK_METHOD(future<Status>,\n",
" MOCK_METHOD(future<StatusOr<$longrunning_deduced_response_type$>>,\n"},
{" $method_name$,\n"
" ($request_type$ const& request), (override));\n\n",},
// clang-format on
Expand Down