Skip to content

Commit 7c91039

Browse files
committed
Address comments
1 parent 64b0d0c commit 7c91039

4 files changed

Lines changed: 15 additions & 13 deletions

File tree

docs/reference-tables/ea-settings.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@
6363
| TLS_PUBLIC_KEY | string | undefined | Base64 Public Key of TSL/SSL certificate | - Value must be a valid base64 string | |
6464
| WARMUP_SUBSCRIPTION_TTL | number | 300000 | TTL for batch warmer subscriptions | - Value must be an integer<br> - Value must be above the minimum<br> - Value must be below the maximum | 0 | 3600000 |
6565
| WS_CONNECTION_OPEN_TIMEOUT | number | 10000 | The maximum amount of time in milliseconds to wait for the websocket connection to open (including custom open handler) | - Value must be an integer<br> - Value must be above the minimum<br> - Value must be below the maximum | 500 | 30000 |
66-
| WS_HEARTBEAT_INTERVAL_MS | number | 10000 | The number of ms between each hearbeat message that EA sends to server | - Value must be an integer<br> - Value must be above the minimum<br> - Value must be below the maximum | 5000 | 300000 |
66+
| WS_HEARTBEAT_INTERVAL_MS | number | 10000 | The number of ms between each hearbeat message that EA sends to server, only works if heartbeat handler is provided | - Value must be an integer<br> - Value must be above the minimum<br> - Value must be below the maximum | 5000 | 300000 |
6767
| WS_SUBSCRIPTION_TTL | number | 120000 | The time in ms a request will live in the subscription set before becoming stale | - Value must be an integer<br> - Value must be above the minimum<br> - Value must be below the maximum | 0 | 3600000 |
6868
| WS_SUBSCRIPTION_UNRESPONSIVE_TTL | number | 120000 | The maximum acceptable time (in milliseconds) since the last message was received and stored in the cache on a WebSocket connection before it is considered unresponsive, causing the adapter to close and attempt to reopen it. | - Value must be an integer<br> - Value must be above the minimum<br> - Value must be below the maximum | 1000 | 180000 |

src/config/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ export const BaseSettingsDefinition = {
250250
validate: validator.integer({ min: 500, max: 30_000 }),
251251
},
252252
WS_HEARTBEAT_INTERVAL_MS: {
253-
description: 'The number of ms between each hearbeat message that EA sends to server',
253+
description:
254+
'The number of ms between each hearbeat message that EA sends to server, only works if heartbeat handler is provided',
254255
type: 'number',
255256
default: 10_000,
256257
validate: validator.integer({ min: 5_000, max: 300_000 }),

src/transports/websocket.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,10 @@ export class WebSocketTransport<
202202

203203
if (this.wsConnection && this.wsConnection.readyState === WebSocket.OPEN) {
204204
try {
205-
logger.debug('Sending WebSocket heartbeat')
205+
logger.debug('Calling heartbeat handler')
206206
await this.config.handlers.heartbeat?.(this.wsConnection, context)
207207
} catch (error) {
208-
logger.warn({ error }, 'Heartbeat handler failed, stopping heartbeat')
209-
this.stopHeartbeat()
208+
logger.warn({ error }, 'Heartbeat handler failed, will be tried later.')
210209
}
211210
} else {
212211
this.stopHeartbeat()

test/transports/websocket.test.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,9 +1156,11 @@ test.serial('sends heartbeat using ping at configured interval', async (t) => {
11561156
},
11571157
})
11581158

1159-
await runAllUntilTime(t.context.clock, HEARTBEAT_INTERVAL)
1159+
const heartBeatRounds = 2
11601160

1161-
t.true(heartbeatCallCount >= 1, `Expected at least 1 heartbeat call, got ${heartbeatCallCount}`)
1161+
await runAllUntilTime(t.context.clock, HEARTBEAT_INTERVAL * heartBeatRounds)
1162+
1163+
t.is(heartbeatCallCount, heartBeatRounds)
11621164

11631165
testAdapter.api.close()
11641166
mockWsServer.close()
@@ -1219,7 +1221,7 @@ test.serial('stops heartbeat when connection closes', async (t) => {
12191221
await t.context.clock.runToLastAsync()
12201222
})
12211223

1222-
test.serial('stops heartbeat when handler throws an error', async (t) => {
1224+
test.serial('does not heartbeat when handler throws an error', async (t) => {
12231225
const base = 'ETH'
12241226
const quote = 'DOGE'
12251227
const HEARTBEAT_INTERVAL = 5000
@@ -1245,9 +1247,7 @@ test.serial('stops heartbeat when handler throws an error', async (t) => {
12451247
},
12461248
() => {
12471249
heartbeatCallCount++
1248-
if (heartbeatCallCount === 1) {
1249-
throw new Error('Heartbeat handler error')
1250-
}
1250+
throw new Error('Heartbeat handler error')
12511251
},
12521252
)
12531253

@@ -1264,9 +1264,11 @@ test.serial('stops heartbeat when handler throws an error', async (t) => {
12641264
},
12651265
})
12661266

1267-
await runAllUntilTime(t.context.clock, HEARTBEAT_INTERVAL * 2)
1267+
const heartBeatRounds = 2
1268+
1269+
await runAllUntilTime(t.context.clock, HEARTBEAT_INTERVAL * heartBeatRounds)
12681270

1269-
t.is(heartbeatCallCount, 1)
1271+
t.is(heartbeatCallCount, heartBeatRounds)
12701272

12711273
testAdapter.api.close()
12721274
mockWsServer.close()

0 commit comments

Comments
 (0)