Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@aprocter
Copy link
Contributor

For the stale-state feature we need a way to block slow paths programmatically in tests.

Motivation

The immediate motivation is to get rid of reliance on (brittle, slow) sleeps in the protocol tests for #5469. We can also use this mechanism in the future to implement position assertion-style tests for stale-state queries.

Test plan

See included automated tests.

@aprocter aprocter requested a review from a team as a code owner March 30, 2022 17:53
@aprocter aprocter requested review from froydnj and removed request for a team March 30, 2022 17:53
Copy link
Contributor

@froydnj froydnj left a comment

Choose a reason for hiding this comment

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

This is a lot nicer than some of the other alternatives I was contemplating.

Comment on lines +456 to +457
slowPathBlockedMutex.Await(absl::Condition(
+[](bool *slowPathBlocked) -> bool { return !*slowPathBlocked; }, &slowPathBlocked));
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the abseil sources, it looks like this can just be:

Suggested change
slowPathBlockedMutex.Await(absl::Condition(
+[](bool *slowPathBlocked) -> bool { return !*slowPathBlocked; }, &slowPathBlocked));
slowPathBlockedMutex.Await(absl::Condition(&slowPathBlocked));

or did you try that already and found that it didn't work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooh, no, let me give it a shot!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, unfortunately this doesn't quite work because the condition we're waiting for is that slowPathBlocked is false, not true. I suppose we could change this internally, but on balance I think the extra complexity here is worth keeping "true means blocked" semantics on the surface and in the implementation. (Glad to change in a later PR if there's objections, though.)

Comment on lines +712 to +716
// We expect the slow path to be blocked, so we want to make sure that we _don't_ receive any messages within a
// pretty long time frame---let's say 2000ms.
{
auto &wrapper = dynamic_cast<MultiThreadedLSPWrapper &>(*lspWrapper);
auto msg = wrapper.read(2000);
Copy link
Contributor

Choose a reason for hiding this comment

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

...and yet, timeouts manage to sneak their way into the patch anyway. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, so unsatisfying! At least there's only one instead of the dozens that #5469 would have needed, I s'pose :)

return;
}

// Test-only hook: Stall for as long as `slowPathBlocked` is set.
Copy link
Contributor

Choose a reason for hiding this comment

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

WDYT about moving this below the ENFORCE(gs->lspQuery.isEmpty()); so it's sort of visually obvious that slowPathBlocked and sleepInSlowPath are doing the same-ish thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call, will do

@aprocter aprocter enabled auto-merge (squash) March 30, 2022 18:24
@aprocter aprocter merged commit 33b3f57 into master Mar 30, 2022
@aprocter aprocter deleted the aprocter/block-slow-path branch March 30, 2022 18:42
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.

3 participants