Skip to content

Commit

Permalink
improvement: tweak tests and uws setup
Browse files Browse the repository at this point in the history
  • Loading branch information
thaaddeus committed Dec 22, 2021
1 parent 9ffc2b8 commit b02b6bc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/tardismachine.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import findMyWay from 'find-my-way'
import http from 'http'
import { clearCache, init } from 'tardis-dev'
import { App, TemplatedApp, WebSocket } from 'uWebSockets.js'
import { App, DISABLED, TemplatedApp, WebSocket } from 'uWebSockets.js'
import { replayHttp, replayNormalizedHttp } from './http'
import { replayNormalizedWS, replayWS, streamNormalizedWS } from './ws'

Expand Down Expand Up @@ -37,7 +37,12 @@ export class TardisMachine {
} as any

this._wsServer = App().ws('/*', {
upgrade: (res, req, context) => {
compression: DISABLED,
maxPayloadLength: 512 * 1024,
idleTimeout: 24 * 60 * 60,
maxBackpressure: 5 * 1024 * 1024,
closeOnBackpressureLimit: true,
upgrade: (res: any, req: any, context: any) => {
res.upgrade(
{ req },
req.getHeader('sec-websocket-key'),
Expand Down Expand Up @@ -70,7 +75,7 @@ export class TardisMachine {
ws.onclose()
}
}
})
} as any)
}

public async start(port: number) {
Expand Down
6 changes: 4 additions & 2 deletions test/tardismachine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ describe('tardis-machine', () => {
]

const options = await Promise.all(
EXCHANGES.filter((e) => e !== 'binance-jersey').map(async (exchange) => {
EXCHANGES.filter((e) => e !== 'binance-jersey' && e !== 'huobi-dm-options' && e !== 'star-atlas').map(async (exchange) => {
const exchangeDetails = await getExchangeDetails(exchange)
const dataTypes: any[] = ['trade', 'trade_bar_10ms', 'book_change', 'book_snapshot_3_0ms']

Expand Down Expand Up @@ -672,7 +672,9 @@ class SimpleWebsocketClient {
private isClosed = false
constructor(url: string, onMessageCB: (message: string) => void, onOpen: () => void = () => {}) {
this._socket = new WebSocket(url)
this._socket.on('message', onMessageCB)
this._socket.on('message', function (message: Buffer) {
onMessageCB(message.toString())
})
this._socket.on('open', onOpen)
this._socket.on('error', (err) => {
console.log('SimpleWebsocketClient Error', err)
Expand Down

0 comments on commit b02b6bc

Please sign in to comment.