-
Notifications
You must be signed in to change notification settings - Fork 1.6k
tests: Improve stability of Subscribe tests #6420
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
base: develop
Are you sure you want to change the base?
Changes from 7 commits
33c0d68
2c660b6
3280979
bec3aea
ce226bd
0739050
4663e6d
d9c46d5
8b70f59
c70f183
2c2d0c2
2591171
68ad67e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ | |
| #include <xrpl/protocol/STTx.h> | ||
|
|
||
| #include <functional> | ||
| #include <future> | ||
| #include <source_location> | ||
| #include <string> | ||
| #include <tuple> | ||
|
|
@@ -393,6 +394,49 @@ class Env | |
| return close(std::chrono::seconds(5)); | ||
| } | ||
|
|
||
| /** Close and advance the ledger, then synchronize with the server's | ||
| io_context to ensure all async operations initiated by the close have | ||
| been started. | ||
|
|
||
| This function performs the same ledger close as close(), but additionally | ||
| ensures that all tasks posted to the server's io_context (such as | ||
| WebSocket subscription message sends) have been initiated before returning. | ||
|
|
||
| What it guarantees: | ||
| - All async operations posted before syncClose() have been STARTED | ||
| - For WebSocket sends: async_write_some() has been called | ||
| - The actual I/O completion may still be pending (async) | ||
|
|
||
| What it does NOT guarantee: | ||
| - Async operations have COMPLETED | ||
| - WebSocket messages have been received by clients | ||
| - However, for localhost connections, the remaining latency is typically | ||
| microseconds, making tests reliable | ||
|
|
||
| Use this instead of close() when: | ||
| - Test code immediately checks for subscription messages | ||
| - Race conditions between test and worker threads must be avoided | ||
| - Deterministic test behavior is required | ||
|
|
||
| @param timeout Maximum time to wait for the barrier task to execute | ||
| @return true if close succeeded and barrier executed within timeout, | ||
| false otherwise | ||
| */ | ||
| [[nodiscard]] bool | ||
| syncClose(std::chrono::system_clock::duration timeout = std::chrono::seconds{1}) | ||
kuznetsss marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| XRPL_ASSERT( | ||
| app().getNumberOfThreads() == 1, | ||
| "syncClose() is only useful on an application with a single thread"); | ||
| auto const result = close(); | ||
| auto server_barrier = std::make_shared<std::promise<void>>(); | ||
|
||
| auto future = server_barrier->get_future(); | ||
| boost::asio::post( | ||
|
||
| app().getIOContext(), [server_barrier]() { server_barrier->set_value(); }); | ||
| auto const status = future.wait_for(timeout); | ||
| return result && status == std::future_status::ready; | ||
kuznetsss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
kuznetsss marked this conversation as resolved.
Show resolved
Hide resolved
kuznetsss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** Turn on JSON tracing. | ||
| With no arguments, trace all | ||
| */ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.