mirror of
https://github.com/XRPLF/rippled.git
synced 2026-07-28 01:20:32 +00:00
test: Improve the server status test to not race and randomly fail (#7304)
Co-authored-by: Alex Kremer <akremer@ripple.com>
This commit is contained in:
committed by
GitHub
parent
b878818e80
commit
20801d98ac
@@ -13,8 +13,9 @@ class WSClient_test : public beast::unit_test::Suite
|
||||
{
|
||||
public:
|
||||
void
|
||||
run() override
|
||||
testSmoke()
|
||||
{
|
||||
testcase("smoke");
|
||||
using namespace jtx;
|
||||
Env env(*this);
|
||||
auto wsc = makeWSClient(env.app().config());
|
||||
@@ -28,6 +29,47 @@ public:
|
||||
auto jv = wsc->getMsg(std::chrono::seconds(1));
|
||||
pass();
|
||||
}
|
||||
|
||||
void
|
||||
testGracefulDisconnect()
|
||||
{
|
||||
testcase("graceful disconnect");
|
||||
using namespace jtx;
|
||||
using namespace std::chrono;
|
||||
|
||||
Env env(*this);
|
||||
auto wsc = makeWSClient(env.app().config());
|
||||
|
||||
// Put real traffic on the connection before closing it.
|
||||
json::Value stream;
|
||||
stream["streams"] = json::ValueType::Array;
|
||||
stream["streams"].append("ledger");
|
||||
auto const sub = wsc->invoke("subscribe", stream);
|
||||
BEAST_EXPECT(sub.isMember("result") || sub.isMember("status"));
|
||||
|
||||
// disconnect() performs a graceful WebSocket closing handshake and
|
||||
// blocks until the server acknowledges. On loopback that completes in
|
||||
// well under its internal 1s timeout; only a broken async_close/ack
|
||||
// coordination would fall through to the force-close path at ~1s. A
|
||||
// generous bound keeps this from flaking under load while still
|
||||
// catching that regression.
|
||||
auto const start = steady_clock::now();
|
||||
wsc->disconnect();
|
||||
auto const elapsed = duration_cast<milliseconds>(steady_clock::now() - start);
|
||||
BEAST_EXPECT(elapsed < milliseconds{750});
|
||||
|
||||
// disconnect() must be idempotent: a second call (and the subsequent
|
||||
// destructor) must not hang, double-close, or crash.
|
||||
wsc->disconnect();
|
||||
pass();
|
||||
}
|
||||
|
||||
void
|
||||
run() override
|
||||
{
|
||||
testSmoke();
|
||||
testGracefulDisconnect();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(WSClient, jtx, xrpl);
|
||||
|
||||
Reference in New Issue
Block a user