Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions packages/xrpl/test/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,13 @@ async function createServer(): Promise<net.Server> {

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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<void>((resolve) => {
Expand Down Expand Up @@ -915,7 +918,7 @@ describe('Connection', function () {
reject(new XrplError('Should not emit error.'))
})

setTimeout(resolve, 5000)
setTimeout(resolve, 500)
})

let disconnectedCount = 0
Expand Down Expand Up @@ -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, [
Expand Down
15 changes: 11 additions & 4 deletions packages/xrpl/test/setupClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Client } from '../src/client'
import { Client, ClientOptions } from '../src/client'

import createMockRippled, {
type MockedWebSocketServer,
Expand All @@ -16,11 +16,14 @@ export interface XrplTestContext {

async function setupMockRippledConnection(
port: number,
options: {
clientOptions?: ClientOptions
} = {},
): Promise<XrplTestContext> {
const context: XrplTestContext = {
mockRippled: createMockRippled(port),
_mockedServerPort: port,
client: new Client(`ws://localhost:${port}`),
client: new Client(`ws://localhost:${port}`, options.clientOptions ?? {}),
servers: [port],
}

Expand All @@ -35,9 +38,13 @@ async function setupMockRippledConnection(
return context.client.connect().then(() => context)
}

async function setupClient(): Promise<XrplTestContext> {
async function setupClient(
options: {
clientOptions?: ClientOptions
} = {},
): Promise<XrplTestContext> {
return getFreePort().then(async (port) => {
return setupMockRippledConnection(port)
return setupMockRippledConnection(port, options)
})
}

Expand Down
Loading