-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Hopefully fix flaky overlay test. #5365
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
Open
graydon
wants to merge
1
commit into
stellar:master
Choose a base branch
from
graydon:repair-overlay-test
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+38
−52
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -545,7 +545,7 @@ TEST_CASE("flow control byte capacity", "[overlay][flowcontrol]") | |
| } | ||
|
|
||
| TEST_CASE("flow control total byte capacity throttles non-flood traffic", | ||
| "[overlay][flowcontrol][!hide]") | ||
| "[overlay][flowcontrol]") | ||
| { | ||
| SCPQuorumSet qSet; | ||
| qSet.threshold = 1; | ||
|
|
@@ -563,7 +563,7 @@ TEST_CASE("flow control total byte capacity throttles non-flood traffic", | |
|
|
||
| auto const msgSize = FlowControlCapacity::msgBodySize(*scpQSetMsg); | ||
| uint64_t constexpr MESSAGES_TO_FLOOR = 3; | ||
| uint64_t constexpr MESSAGES_PER_BURST = MESSAGES_TO_FLOOR + 1; | ||
| size_t constexpr NUM_CYCLES = 100; | ||
| auto const byteCapacity = msgSize * MESSAGES_TO_FLOOR - 1; | ||
| auto const totalCapacity = | ||
| FlowControlByteCapacity::BYTE_CAPACITY_READ_FLOOR + byteCapacity; | ||
|
|
@@ -621,33 +621,21 @@ TEST_CASE("flow control total byte capacity throttles non-flood traffic", | |
| .getOverlayMetrics() | ||
| .mConnectionReadThrottle.count(); | ||
| }; | ||
| auto waitFor = [&](std::string const& phase, auto&& predicate) { | ||
| auto timeout = std::chrono::seconds(10); | ||
| auto start = std::chrono::steady_clock::now(); | ||
|
|
||
| while (!predicate() && | ||
| std::chrono::steady_clock::now() - start <= timeout) | ||
| { | ||
| if (simulation->crankAllNodes() == 0) | ||
| { | ||
| std::this_thread::sleep_for(std::chrono::milliseconds(1)); | ||
| } | ||
| } | ||
| auto getRecvCount = [&]() { | ||
| return app2->getOverlayManager() | ||
| .getOverlayMetrics() | ||
| .mRecvSCPQuorumSetTimer.count(); | ||
| }; | ||
|
|
||
| auto capacity = getReceiverCapacity(); | ||
| CAPTURE(phase); | ||
| CAPTURE(capacity.mTotalCapacity); | ||
| CAPTURE(totalCapacity); | ||
| CAPTURE(capacity.mFloodCapacity); | ||
| CAPTURE(receiver->getFlowControl()->isThrottled()); | ||
| CAPTURE(receiver->getFlowControl()->canRead()); | ||
| CAPTURE(sender->isConnectedForTesting()); | ||
| CAPTURE(receiver->isConnectedForTesting()); | ||
| CAPTURE(getReadThrottleCount()); | ||
| simulation->crankUntil( | ||
| [&]() { | ||
| return getReceiverCapacity().mTotalCapacity == totalCapacity && | ||
| !receiver->getFlowControl()->isThrottled(); | ||
| }, | ||
| std::chrono::seconds(10), false); | ||
| auto const initialCapacity = getReceiverCapacity(); | ||
|
|
||
| REQUIRE(predicate()); | ||
| }; | ||
| auto waitForReceiverThrottle = [&]() { | ||
| auto waitForThrottle = [&](size_t cycle) { | ||
| auto timeout = std::chrono::seconds(10); | ||
| auto start = std::chrono::steady_clock::now(); | ||
|
|
||
|
|
@@ -658,6 +646,7 @@ TEST_CASE("flow control total byte capacity throttles non-flood traffic", | |
| } | ||
|
|
||
| auto capacity = getReceiverCapacity(); | ||
| CAPTURE(cycle); | ||
| CAPTURE(capacity.mTotalCapacity); | ||
| CAPTURE(totalCapacity); | ||
| CAPTURE(capacity.mFloodCapacity); | ||
|
|
@@ -668,44 +657,41 @@ TEST_CASE("flow control total byte capacity throttles non-flood traffic", | |
| CAPTURE(getReadThrottleCount()); | ||
|
|
||
| REQUIRE(receiver->getFlowControl()->isThrottled()); | ||
| }; | ||
| auto drainReceiver = [&]() { | ||
| waitFor("receiver drains", [&]() { | ||
| return getReceiverCapacity().mTotalCapacity == totalCapacity && | ||
| !receiver->getFlowControl()->isThrottled(); | ||
| }); | ||
| REQUIRE(getReceiverCapacity().mTotalCapacity == totalCapacity); | ||
| REQUIRE(!receiver->getFlowControl()->isThrottled()); | ||
| }; | ||
|
|
||
| drainReceiver(); | ||
| auto const initialFloodCapacity = getReceiverCapacity().mFloodCapacity; | ||
| auto requireReceiverTotalCapacity = [&](uint64_t total) { | ||
| auto capacity = getReceiverCapacity(); | ||
| REQUIRE(capacity.mTotalCapacity == total); | ||
| REQUIRE(capacity.mFloodCapacity == initialFloodCapacity); | ||
| REQUIRE(capacity.mTotalCapacity == | ||
| FlowControlByteCapacity::BYTE_CAPACITY_READ_FLOOR - 1); | ||
| REQUIRE(capacity.mFloodCapacity == initialCapacity.mFloodCapacity); | ||
| }; | ||
|
|
||
| requireReceiverTotalCapacity(totalCapacity); | ||
| REQUIRE(initialCapacity.mTotalCapacity == totalCapacity); | ||
| REQUIRE(receiver->getFlowControl()->canRead()); | ||
| REQUIRE(!receiver->getFlowControl()->isThrottled()); | ||
| REQUIRE(initialCapacity.mFloodCapacity == | ||
| app2->getOverlayManager().getFlowControlFloodByteCapacity()); | ||
|
|
||
| for (size_t i = 0; i < 100; ++i) | ||
| for (size_t cycle = 0; cycle < NUM_CYCLES; ++cycle) | ||
| { | ||
| CAPTURE(i); | ||
| drainReceiver(); | ||
| CAPTURE(cycle); | ||
| auto const initialReadThrottleCount = getReadThrottleCount(); | ||
| CAPTURE(initialReadThrottleCount); | ||
| for (size_t j = 0; j < MESSAGES_PER_BURST; ++j) | ||
| auto const initialRecvCount = getRecvCount(); | ||
| for (size_t i = 0; i < MESSAGES_TO_FLOOR; ++i) | ||
| { | ||
| sender->sendMessage(scpQSetMsg); | ||
| } | ||
|
|
||
| waitForReceiverThrottle(); | ||
| drainReceiver(); | ||
| waitForThrottle(cycle); | ||
| simulation->crankUntil( | ||
| [&]() { | ||
| return getRecvCount() == initialRecvCount + MESSAGES_TO_FLOOR; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this a race? The metric is updated before msg destructor is called, which releases capacity. |
||
| }, | ||
| std::chrono::seconds(10), false); | ||
|
|
||
| auto const finalCapacity = getReceiverCapacity(); | ||
| REQUIRE(getRecvCount() == initialRecvCount + MESSAGES_TO_FLOOR); | ||
| REQUIRE(getReadThrottleCount() > initialReadThrottleCount); | ||
| requireReceiverTotalCapacity(totalCapacity); | ||
| REQUIRE(finalCapacity.mTotalCapacity == initialCapacity.mTotalCapacity); | ||
| REQUIRE(finalCapacity.mFloodCapacity == initialCapacity.mFloodCapacity); | ||
| REQUIRE(receiver->getFlowControl()->canRead()); | ||
| REQUIRE(!receiver->getFlowControl()->isThrottled()); | ||
| REQUIRE(sender->isConnectedForTesting()); | ||
| REQUIRE(receiver->isConnectedForTesting()); | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
std::this_thread::sleep_for(std::chrono::milliseconds(1));correct here? Does it work with Simulation class, which cranks virtual time separately?It's not a common pattern across our test suite, so I wanted to confirm that we're confident this is the right fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@graydon I don't want to block this change since CI is unstable - we can merge as-is if you want. However, I'm still not sure if we should sleep at all. Wouldn't anything time-based like this continue to cause flakiness depending on how fast messages get processed/tasks are scheduled on main?
One way around that is to make the test simpler: we can just let it crank for a while, then check in metrics that core throttled connections the number of times we expect and that peers are still connected. Of course, we can't assert concrete checks like "reading capacity is N", but presumably the invariance in the code already does the heavy lifting for us (e.g. capacity can't go negative, capacity can't go over the limit, etc). I would only add an assert in the test that reading capacity is higher than flood capacity, to make sure that if we there's a bug and flood capacity is touched for some reason, we trigger an error of sorts. Up to you though.