From 925f0196f5171d268dea6ceb62d8b79225464490 Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Mon, 20 Oct 2025 17:59:38 -0400 Subject: [PATCH 1/3] shave 7 seconds off of connections.test.ts --- packages/xrpl/test/connection.test.ts | 8 ++++++-- packages/xrpl/test/setupClient.ts | 15 +++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/xrpl/test/connection.test.ts b/packages/xrpl/test/connection.test.ts index af7af5e691..d70beea440 100644 --- a/packages/xrpl/test/connection.test.ts +++ b/packages/xrpl/test/connection.test.ts @@ -84,7 +84,11 @@ describe('Connection', function () { beforeEach(async () => { // console.log(`before: `, expect.getState().currentTestName) - clientContext = await setupClient() + clientContext = await setupClient({ + clientOptions: { connectionTimeout: 500 }, + }) + jest.useRealTimers() + start = performance.now() }) afterEach(async () => { // console.log(`after: `, expect.getState().currentTestName) @@ -425,7 +429,7 @@ describe('Connection', function () { } catch (error) { // @ts-expect-error -- Error has a message expect(error.message).toEqual( - "Error: connect() timed out after 5000 ms. If your internet connection is working, the rippled server may be blocked or inaccessible. You can also try setting the 'connectionTimeout' option in the Client constructor.", + "Error: connect() timed out after 500 ms. If your internet connection is working, the rippled server may be blocked or inaccessible. You can also try setting the 'connectionTimeout' option in the Client constructor.", ) expect(spy).toHaveBeenCalled() // @ts-expect-error -- Promise throws timeout error after test is done diff --git a/packages/xrpl/test/setupClient.ts b/packages/xrpl/test/setupClient.ts index ca365be25f..0da756ddf0 100644 --- a/packages/xrpl/test/setupClient.ts +++ b/packages/xrpl/test/setupClient.ts @@ -1,4 +1,4 @@ -import { Client } from '../src/client' +import { Client, ClientOptions } from '../src/client' import createMockRippled, { type MockedWebSocketServer, @@ -16,11 +16,14 @@ export interface XrplTestContext { async function setupMockRippledConnection( port: number, + options: { + clientOptions?: ClientOptions + } = {}, ): Promise { const context: XrplTestContext = { mockRippled: createMockRippled(port), _mockedServerPort: port, - client: new Client(`ws://localhost:${port}`), + client: new Client(`ws://localhost:${port}`, options.clientOptions ?? {}), servers: [port], } @@ -35,9 +38,13 @@ async function setupMockRippledConnection( return context.client.connect().then(() => context) } -async function setupClient(): Promise { +async function setupClient( + options: { + clientOptions?: ClientOptions + } = {}, +): Promise { return getFreePort().then(async (port) => { - return setupMockRippledConnection(port) + return setupMockRippledConnection(port, options) }) } From fbc27cb67aded797bf3dbfda0123f58670bd2308 Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Mon, 20 Oct 2025 18:04:04 -0400 Subject: [PATCH 2/3] shrink timeouts --- packages/xrpl/test/connection.test.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/xrpl/test/connection.test.ts b/packages/xrpl/test/connection.test.ts index d70beea440..0d64efdf74 100644 --- a/packages/xrpl/test/connection.test.ts +++ b/packages/xrpl/test/connection.test.ts @@ -87,8 +87,6 @@ describe('Connection', function () { clientContext = await setupClient({ clientOptions: { connectionTimeout: 500 }, }) - jest.useRealTimers() - start = performance.now() }) afterEach(async () => { // console.log(`after: `, expect.getState().currentTestName) @@ -640,7 +638,7 @@ describe('Connection', function () { reject(new XrplError(`should not throw error, got ${String(error)}`)) }) - setTimeout(resolve, 5000) + setTimeout(resolve, 500) }) const disconnectedPromise = new Promise((resolve) => { @@ -919,7 +917,7 @@ describe('Connection', function () { reject(new XrplError('Should not emit error.')) }) - setTimeout(resolve, 5000) + setTimeout(resolve, 500) }) let disconnectedCount = 0 @@ -1019,7 +1017,7 @@ describe('Connection', function () { // wait to ensure that XrplError is not thrown after test is done await new Promise((resolve) => { - setTimeout(resolve, 2000) + setTimeout(resolve, 1500) }) assert.includeMembers(traceMessages, [ From f60481b5078dba56ca70a0149a652146d2c2c85d Mon Sep 17 00:00:00 2001 From: Mayukha Vadari Date: Mon, 20 Oct 2025 18:07:15 -0400 Subject: [PATCH 3/3] more reasonable values --- packages/xrpl/test/connection.test.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/xrpl/test/connection.test.ts b/packages/xrpl/test/connection.test.ts index 0d64efdf74..c23b55a135 100644 --- a/packages/xrpl/test/connection.test.ts +++ b/packages/xrpl/test/connection.test.ts @@ -81,11 +81,12 @@ async function createServer(): Promise { describe('Connection', function () { let clientContext: XrplTestContext + const CONNECTION_TIMEOUT = 1000 beforeEach(async () => { // console.log(`before: `, expect.getState().currentTestName) clientContext = await setupClient({ - clientOptions: { connectionTimeout: 500 }, + clientOptions: { connectionTimeout: CONNECTION_TIMEOUT }, }) }) afterEach(async () => { @@ -427,7 +428,7 @@ describe('Connection', function () { } catch (error) { // @ts-expect-error -- Error has a message expect(error.message).toEqual( - "Error: connect() timed out after 500 ms. If your internet connection is working, the rippled server may be blocked or inaccessible. You can also try setting the 'connectionTimeout' option in the Client constructor.", + `Error: connect() timed out after ${CONNECTION_TIMEOUT} ms. If your internet connection is working, the rippled server may be blocked or inaccessible. You can also try setting the 'connectionTimeout' option in the Client constructor.`, ) expect(spy).toHaveBeenCalled() // @ts-expect-error -- Promise throws timeout error after test is done