diff --git a/packages/xrpl/test/connection.test.ts b/packages/xrpl/test/connection.test.ts index af7af5e691..c23b55a135 100644 --- a/packages/xrpl/test/connection.test.ts +++ b/packages/xrpl/test/connection.test.ts @@ -81,10 +81,13 @@ 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() + clientContext = await setupClient({ + clientOptions: { connectionTimeout: CONNECTION_TIMEOUT }, + }) }) afterEach(async () => { // console.log(`after: `, expect.getState().currentTestName) @@ -425,7 +428,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 ${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 @@ -636,7 +639,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) => { @@ -915,7 +918,7 @@ describe('Connection', function () { reject(new XrplError('Should not emit error.')) }) - setTimeout(resolve, 5000) + setTimeout(resolve, 500) }) let disconnectedCount = 0 @@ -1015,7 +1018,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, [ 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) }) }