-
-
Notifications
You must be signed in to change notification settings - Fork 469
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
Memory leak in integration tests #83
Comments
We are having memory leak issue in integration tests. This is an integration test for import { INestApplication, Query } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { rest } from 'msw';
import { setupServer } from 'msw/node';
import { AppModule } from 'src/app.module';
import request from 'supertest';
const server = setupServer();
describe(<name>, () => {
let app: INestApplication;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();
app = module.createNestApplication();
await app.init();
});
beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());
it(<name>, () => {
server.use(
rest.get(<endpoint>, (req, res, ctx) => {
return res(ctx.status(500));
}),
);
const query = <query>;
return request(app.getHttpServer())
.post('/graphql')
.send({
operationName: <operation-name>,
query,
variables: <variables>,
})
.expect(200)
.expect({
data: <data>,
});
});
afterAll(async () => {
await app.close();
});
}); And after running the test we get the jest memory leak warning you mentioned earlier. Running tests with
And this is the error stack:
Running test not using |
@c0m1t Is this just psuedo-code you pasted above? If not, there are a handful of issues with it from what I can see. Could you perhaps paste the real usage, as well as what your default server/handlers look like? I don't know how nestjs builds requests, but Also, if you're using superagent, you should just superagent directly in the tests (instead of supertest), and let msw intercept the actual network request. I don't think providing the |
@msutkowski
This is the official NestJS documentation about End-to-end testing. |
@c0m1t, may I please ask you to ensure you're using the latest version of In particular, $ npm ls node-request-interceptor |
@kettanaito
The thing is executing the |
Just to clarify: is there a memory leak warning or NodeJS heap stack trace? A pending handler in a test doesn't necessarily mean a memory leak. It can be an async task that never finished, for example. Can you try your test without |
@kettanaito It is the same jest warning you mentioned in the first post:
I do my best to do that. Thank you |
Current setup of integration tests does not handle certain asynchronous operations in its setup well, which results into memory leaks often happening when testing locally.
Details
Jest warning
Memory leak exception
Expected behavior
runBrowserWith
andspawnServer
utilities have tests that assert they clean up after themselves (i.e. asserting no process is running at the port previously occupied by the server after closing)Area of effect
runBrowserWith
spawnServer
The text was updated successfully, but these errors were encountered: