CodeOwnersOnAddReviewer: Post change message asynchronously

Computing the owned path is rather expensive and adds latency to
PostReviewers and PostReview calls. Avoid the extra latency by posting
the message asynchronously. This is especially important if multiple
code owners are added as reviewers at once via PostReview, as in this
case the latency increases linearly with the number of added code
owners.

Posting the change message asynchronously means that possible errors
during the posting of the change message are ignored, but we are fine
with this since we already have retrying in place, we properly log the
error and a missing change message is only a small annoyance, but not a
severe issue.

For posting the change message asynchronously we must open a request
context that provides the current user, otherwise getting the current
user in the background thread fails (e.g. the current user is needed as
the author of the change message).

Posting the change message asynchronously in tests makes the tests prone
to fail with LOCK_FAILURE since change updates that are triggered by the
tests after adding a reviewer are done in parallel with the asynchronous
posting of the change message. While the REST API has retries in place
to account for this, the test API does not retry on LOCK_FAILUREs.
That's why we disable the asynchronous posting of change messages in
tests (via a config option). This also makes the assertions in
CodeOwnersOnAddReviewerIT easier since they do not need to wait until
the asynchronous posting of the change messages happened before they can
assert it. The test in CodeOwnersOnAddReviewerIT that verifies the
asynchronous posting of the change message explicitly sets the config
parameter to enable asynchronous posting of change messages.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: Icb55023c989e3ae14ff64ddc8a79130af71efd92
10 files changed
tree: 7d4fc0ebb65b0ad694ca35290a298c6128fc78f0
  1. java/
  2. javatests/
  3. proto/
  4. resources/
  5. test/
  6. ui/
  7. .eslintrc.json
  8. .gitignore
  9. .gitreview
  10. bower.json
  11. BUILD
  12. LICENSE
  13. package-lock.json
  14. package.json
  15. README.md
README.md

Gerrit Code Review code-owners plugin

This plugin provides support for defining code owners for files in a repository.

If the code-owners plugin is enabled, changes can only be submitted if all touched files are covered by approvals from code owners.

Also see resources/Documentation/about.md.

IMPORTANT: Before installing/enabling the plugin follow the instructions from the setup guide, see resources/Documentation/setup-guide.md.