Issue #6 - Live tests#14
Conversation
…ld break the tests after the first one
…ld break the tests after the first one
lekkas
left a comment
There was a problem hiding this comment.
- See comments on optimizing the process by waiting for all websocket events only once.
- While I'd love to run these tests on every PR, I am not sure they'll run reliably on github's workers and may fail intermittently. I'd recommend we only run the live tests as part of the
npm publishworfklow, so it'll run locally on the publisher's machine before the npm package is updated.
What do you think?
| let stream: WSSubscriptionManager | undefined; | ||
|
|
||
| beforeEach(async () => { | ||
| tokenIdsArray = await getTopMarketsByVolume(marketsQty); |
There was a problem hiding this comment.
@TheyCallMeCheng instead of fetching the markets every single time, I'd recommend we use the following flow:
- Call
getTopMarketsByVolumeandcreateConnectionWithTypeonce once (perhaps using abeforeAllhook) - Wait until all events types have been received. On a relevant note, let's increase the hook timeout to 2 minutes in
vitest.config.ts - Then proceed with each separate test that confirm all fields exists & no additional fields are present.
| import { WSSubscriptionManager } from '../../src/WSSubscriptionManager' | ||
| import { BookEvent, LastTradePriceEvent, PriceChangeEvent, PriceChangeItem, TickSizeChangeEvent, WebSocketHandlers } from '../../src/types/PolymarketWebSocket' | ||
|
|
||
| const marketsQty = '50'; |
There was a problem hiding this comment.
Let's increase that to 100; it makes no real difference in terms of performance and will increase the chances that we catch all websocket events faster.
|
Thank you for the suggestions, I have implemented:
About the last point, it increased performance 10x, so from 120s it now only takes between 3s and 12s to run live tests. I kept them separate per describe block for better test isolation and maintainability, and I don't think sharing a single connection across all tests would improve the performance significantly. |
|
This is in a much better direction, thank you!
Why do we need to re-fetch / re-connect on each
describe('onBook', () => { // ..
describe('onLastTradePrice', () => { // ..
describe('onPriceChange', () => { // .. |
|
Fixed, now we fetch first, wait for all events and then test. |
Sweet!! I just tested it locally and runs perfectly, great work! |
Regarding issue #6