-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: update test memory leaks #2394
Conversation
✅ Deploy Preview for brilliant-pasca-3e80ec canceled.
|
@@ -43,7 +43,6 @@ | |||
"jest": "^29.7.0", | |||
"npm-run-all2": "^5.0.2", | |||
"prettier": "^3.2.4", | |||
"ts-jest": "^29.1.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we use @swc/jest
instead, not needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like its used here? https://github.com/interledger/rafiki/blob/main/jest.config.js#L4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BlairCurrey was about to merge until I saw this, fixed now 👍
if (this.apolloServer) { | ||
await this.apolloServer.stop() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we do plugins: [ApolloServerPluginDrainHttpServer({ httpServer })]
when creating the apollo server, the httpServer will be automatically stopped/connections will be drained. However, before we weren't closing the actual apollo server that does other operations as well: https://www.apollographql.com/docs/apollo-server/api/apollo-server/#stop
await redis.flushall() | ||
}) | ||
|
||
afterAll(async () => { | ||
redis.disconnect() | ||
jest.useRealTimers() | ||
await redis.quit() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems to be the preferred way to stop redis connections: redis/ioredis#1088
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about resetting the timers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved it to the afterEach
@@ -33,10 +36,14 @@ describe('Accounting Service', (): void => { | |||
} | |||
|
|||
beforeAll(async (): Promise<void> => { | |||
const { port } = await startTigerbeetleContainer() | |||
Config.tigerbeetleReplicaAddresses = [port.toString()] | |||
const tigerbeetlePort = (global as unknown as { tigerbeetlePort: number }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gets injected via the tigerbeetle test environment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this suggestion applies here as well: https://github.com/interledger/rafiki/pull/2394/files#r1480529987
@@ -106,7 +112,7 @@ describe('Accounting Service', (): void => { | |||
}, | |||
LiquidityAccountType.ASSET | |||
) | |||
).rejects.toThrowError( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using toThrowError
gave me a deprecated warning
@@ -5,7 +5,7 @@ import { faker } from '@faker-js/faker' | |||
|
|||
export const IlpPrepareFactory = Factory.define<IlpPrepare>('IlpPrepare').attrs( | |||
{ | |||
amount: faker.finance.amount(1, 100, 0), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this type signature is deprecated (was giving me warnings)
@@ -0,0 +1,9 @@ | |||
import { TestEnvironment } from 'jest-environment-node' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Main change. Described here: nock/nock#2358
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess these nock changes are needed even after this fix? nock/nock#2572 It looks like we are on the latest and have this fix. I suppose there were two issues:
- nock leaking from simply being imported (fixed above)
- us not cleaning it up properly which still require these changes
/** | ||
* @jest-environment ./packages/backend/jest.tigerbeetle-environment.ts | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
specifies specific environment for this test suite
I was not familiar with |
@@ -20,6 +19,8 @@ import { CreateOrUpdatePeerByUrlInput } from '../generated/graphql' | |||
import { AutoPeeringService } from '../../payment-method/ilp/auto-peering/service' | |||
import { v4 as uuid } from 'uuid' | |||
|
|||
const nock = (global as unknown as { nock: typeof import('nock') }).nock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about this?
add this to a new file at rafiki/packages/backend/src/global.d.ts
:
declare module globalThis {
var nock: typeof import('nock')
}
which lets us just do:
const nock = global.nock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I dont love that this suggests nock is on global anywhere (including outside tests, or outside the that specific test environment) ... was just thinking maybe we could avoid doing all this casting every time we want to use it. alternatively maybe we can initialize it like this once somewhere and export it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too fond of this long casting, but I think I prefer not mixing the shipped code vs the testing code IMO
Runs fine for me locally (including |
Very interesting. I think we should give it a try. I also didn't know that flag. |
@mkurapov |
# Conflicts: # package.json # pnpm-lock.yaml
@BlairCurrey https://github.com/interledger/rafiki/actions/runs/7919005784/job/21618820101 (6 mins) |
This reverts commit 9b4b53e.
Are we ready to get this merged as is then? |
@sabineschaller going to try one final test to move some imports around to see if the "fix" from the nock issue might work for us, otherwise, I'll merge |
@sabineschaller yeah, the order of imports don't seem to make a difference in the repo |
Good to know, thanks for testing it out. |
# Conflicts: # packages/backend/package.json # packages/backend/src/index.ts # packages/backend/src/tests/app.ts # pnpm-lock.yaml
Changes proposed in this pull request
nock
, backend tests can now be run serially (via--runInBand
) without running out of memory. This was verified using the--detectLeaks
flag for jest tests, which would throw an error if detected a memory leak during a test.when running the test:ci command, but at 100% workers, it still appears on my machine 🤷 . But at least some progress there.
Context
Fixes #2393
Fixes #1094 (even though it seemed like the thread panic wasn't an issue with newer versions of tigerbeetle)
Checklist
fixes #number