Skip to content

docs: user guide for mocking LRO errors#1722

Merged
dbolduc merged 3 commits intogoogleapis:mainfrom
dbolduc:ug-mock-lro-error
Apr 15, 2025
Merged

docs: user guide for mocking LRO errors#1722
dbolduc merged 3 commits intogoogleapis:mainfrom
dbolduc:ug-mock-lro-error

Conversation

@dbolduc
Copy link
Member

@dbolduc dbolduc commented Apr 5, 2025

Fixes #1661

Describe how to simulate different types of LRO errors in tests in the user guide.

Looks like: mocking_lros_error.pdf

@codecov
Copy link

codecov bot commented Apr 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.09%. Comparing base (0923577) to head (bdfeb34).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1722   +/-   ##
=======================================
  Coverage   96.09%   96.09%           
=======================================
  Files          54       54           
  Lines        1998     1998           
=======================================
  Hits         1920     1920           
  Misses         78       78           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dbolduc dbolduc marked this pull request as ready for review April 5, 2025 18:21
Comment on lines +172 to +181
The simplest way to simulate an error is to have the initial request fail with
an error.

```rust,ignore,noplayground
{{#rustdoc_include ../samples/tests/mocking_lros_error.rs:expectation-initial}}
```
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is subject to the retry policy. You should say something about returning an error that is not retryable.

Copy link
Member Author

Choose a reason for hiding this comment

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

The stubbed out clients do not have policies. I moved the blurb that says that up to the initial section of the error handling. (it was formerly tucked away in the last of the subsections).

mock.expect_get_operation()
.once()
.in_sequence(&mut seq)
.returning(|_, _| Err(Error::other("could not poll operation")));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be more interesting to return realistic errors here, like a ServiceError with Code::Aborted or something. If you are writing tests that return errors, it is because your code handles realistic errors, we need to feed it realistic errors too. If not, we should explain that we are using Error::other to simplify the tests, and that real RPCs return something different.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@dbolduc dbolduc force-pushed the ug-mock-lro-error branch from 94ba360 to bdfeb34 Compare April 15, 2025 15:44
@dbolduc dbolduc merged commit a7c42d2 into googleapis:main Apr 15, 2025
21 checks passed
@dbolduc dbolduc deleted the ug-mock-lro-error branch April 15, 2025 15:59
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.

User-guide section on how to test LROs

2 participants