I'm having strange issue with testing on nestjs.
When I'm running npm run test, most of the tests fails. Some variables are becoming undefined, nest cannot resolve dependencies etc.
But when I'm running ALL TESTS from WebStorm panel, everything works fine.
https://gist.github.com/hejkerooo/5a56ee2a7d78ce41cb390d1ece648933
Nest can't resolve dependencies of the TrendService (?). Please make sure that the argument at index [0] is available in the _RootTestModule context.
at Injector.lookupComponentInExports (node_modules/#nestjs/core/injector/injector.js:180:19)
Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.
at mapper (node_modules/jest-jasmine2/build/queueRunner.js:25:45)
TypeError: Cannot read property 'clear' of undefined
17 | beforeEach(async () => {
18 | jest.restoreAllMocks();
> 19 | await trendsRepository.clear();
| ^
20 | });
21 |
22 | afterAll(async () => {
ReferenceError: You are trying to `import` a file after the Jest environment has been torn down.
(node:2633) UnhandledPromiseRejectionWarning: TypeError: Caught error after test environment was torn down
The issue has been resolved - just used jest.setTimeout to 50000, works fine.
I assume it's a temporary fix, but will dig into it.
Related
Postgres 14
prisma 2
Azure Database
Faced an error during seeding development DB
remaining connection slots are reserved for non-replication superuser connections
I found that this error is caused by lack of connection pool. After some struggling, I failed.
Here are my tries.
checked session leaks(not found)
increase 'max_connections' value in /etc/postgresql/14/postgresql.conf
reboot DB
reboot local node.js app which uses the remote DB
Full logs are below.
PrismaClientUnknownRequestError:
Invalid `prisma.problem.create()` invocation in
/myproject/api/prisma/seed.ts:448:43
445
446 await Promise.all(
447 problemData.map(async (data) => {
→ 448 const newOne = await prisma.problem.create(
Error in connector: Error querying the database: db error: FATAL: remaining connection slots are reserved for non-replication superuser connections
at RequestHandler.request (/myproject/api/node_modules/#prisma/client/runtime/index.js:49026:15)
at async PrismaClient._request (/myproject/api/node_modules/#prisma/client/runtime/index.js:49919:18)
at async /myproject/api/prisma/seed.ts:448:22
at async Promise.all (index 11)
at async main (/myproject/api/prisma/seed.ts:446:3) {
clientVersion: '3.15.2'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
An error occured while running the seed command:
Error: Command failed with exit code 1: yarn seed
We have ReactJS + NodeJS backend app running in Google GCP App Engine, but what we are experiencing is server down time for few min randomly. We have info Logs and error logs in code almost every api and every major functions and all catch blocks. I have also put global exception catch block
process.on('uncaughtException', (error) => {
Logger.error('--- Exception -----', error);
});
I also have error handler middleware my expressjs
app.use(function(error, req, res, next) {
if (error && error.stack && error.message) {
//cluster.worker.disconnect();
Logger.error('---- Global Exception Handler : error ---- ', error);
}
// Any request to this server will get here, and will send an HTTP
// response with the error message 'woops'
res.json({ status: 'FAIL', message: error.message });
});
but whenever server restarts by itself i don't see any exception in logs, it doesn't even appear in process.on('uncaughtException' block also.
One observation is GCP App engine is auto scaling when there is more traffic, but app is going down whenever there more traffic despite auto scaling is happening.
I want to know how to handle this, how to debug this to identify where exactly the issue is, is the issue is at code level if so why none of the exceptions are caught? or the issue is with GCP?
our production server also goes down many times randomly.
I tried using longjohn and setting NODE_DEBUG environment variable to net to get some hint as suggested in other SO Post
Update 1 :
We Ran Jmeter Performance test to check whether load on server is the main reason, as Rafael Lemos rightly pointed in comment, in our case "The instance exceeds the maximum memory for its configured instance_class" may be the reason behind server going down, with lot of trail and error, when we made minimum no of instances = 2 we are not observing server going down.
However jmeter tests are all running fine but when we do jmeter test as well as manual testing at a time , we are observing Socket Hangup Exception, this crash happens immediately as soon as we start using front end app, where as jmeter tests access our backend app. Both backend and front end are running in same app engine.
Kindly find our observations below
Now question is Why Socket Hangup is coming, when I explored this, I found a solution in some other SO post, to handle socket hangup exception I have put below code in app.js but its not working
app.use((req, res, next) => {
if(res.socket.destroyed) {
console.log('----- socketIsDestroyed-- ', res.socket.destroyed);
res.end();
} else {
console.log('----- socketNotDestroyed-- ', res.socket.destroyed);
next();
}
})
And in Google App Engine Sys logs I see following error log multiple times
GET 503 /readiness_check failReason:"app lameducked"
Update2: my app.yaml file , is issue with resource limits ?
runtime: nodejs
env: flex
automatic_scaling:
min_num_instances: 2
max_num_instances: 5
resources:
cpu: .5
memory_gb: 0.9
disk_size_gb: 10
env_variables:
<Many Environment Variables here>
Update3: when we increased resource limit we are observing frequency of server going down is lesser, updated resource limit are as follows. Is it all because of memory limit issues ?
resources:
cpu: 2
memory_gb: 7.5
disk_size_gb: 10
Logs recorded while Socket hangup exception is as below
A 2021-02-25T05:17:16Z 1|dev_client | Error: socket hang up
A 2021-02-25T05:17:16Z 1|dev_client | at createHangUpError (_http_client.js:323:15)
A 2021-02-25T05:17:16Z 1|dev_client | at Socket.socketCloseListener (_http_client.js:364:25)
A 2021-02-25T05:17:16Z 1|dev_client | at Socket.emit (events.js:203:15)
A 2021-02-25T05:17:16Z 1|dev_client | at TCP._handle.close (net.js:606:12)
A 2021-02-25T05:17:16Z 1|dev_client | Error: socket hang up
A 2021-02-25T05:17:16Z 1|dev_client | at createHangUpError (_http_client.js:323:15)
A 2021-02-25T05:17:16Z 1|dev_client | at Socket.socketCloseListener (_http_client.js:364:25)
A 2021-02-25T05:17:16Z 1|dev_client | at Socket.emit (events.js:203:15)
A 2021-02-25T05:17:16Z 1|dev_client | at TCP._handle.close (net.js:606:12)
A 2021-02-25T05:17:16.691Z GET 499 0 B 6 s Firefox 85 /api/volunteercampaigns/6037246c4de6880024f01ff3/prominentVolunteers GET 499 0 B 6 s Firefox 85
A 2021-02-25T05:17:16.700Z GET 499 0 B 6 s Firefox 85 /api/volunteercampaigns/6037246c4de6880024f01ff3/prominentVolunteers GET 499 0 B 6 s Firefox 85
A 2021-02-25T05:17:17Z PM2 | App name:dev_client id:1 disconnected
A 2021-02-25T05:17:17Z PM2 | App [dev_client:1] exited with code [0] via signal [SIGINT]
A 2021-02-25T05:17:17Z PM2 | App [dev_client:1] starting in -cluster mode-
A 2021-02-25T05:17:17Z PM2 | App name:dev_client id:1 disconnected
A 2021-02-25T05:17:17Z PM2 | App [dev_client:1] exited with code [0] via signal [SIGINT]
A 2021-02-25T05:17:17Z PM2 | App [dev_client:1] starting in -cluster mode-
A 2021-02-25T05:17:18Z PM2 | App [dev_client:1] online
A 2021-02-25T05:17:18Z PM2 | App [dev_client:1] online
potentially related issues
#795
Description
I am new to using Detox but it appears to me that primitives are not being properly set as jest globals following the setup and usage guides I could find in the documentation. I get the code in the console ReferenceError: element is not defined. Maybe there is a way to improve the logging to clarify these config errors for good
Repo to reproduce:
https://github.com/Kielan/OnyxWalletReactNative
Detox v8.1.6^
Node v8.9.4,
React Native v0.56.0
Device iphone 7 sim release and debug
Device and verbose Detox logs
ReferenceError: element is not defined
14 | })
15 |
> 16 | it(':ios: shows splash screen and then login', async () => {
| ^
17 | await expect(element(by.label('animateLoginLabel'))).toBeVisible()
I am facing issue when I run my tests with mocha-allure-reporter ,the tests are running successfully with mocha ,but mocha --reporter mocha-allure-reporter returns the following error
> notifications-api#1.0.0 test /app
> mocha --reporter mocha-allure-reporter
2016-11-15T06:13:26.762Z - info: Notification API up and running on port 4000
2016-11-15T06:13:26.773Z - error: Tue, 15 Nov 2016 06:13:26 GMT uncaughtException
2016-11-15T06:13:26.775Z - error: TypeError: test.currentRetry is not a function
at Runner.<anonymous> (/app/node_modules/mocha-allure-reporter/index.js:29:19)
at emitOne (events.js:77:13)
at Runner.emit (events.js:169:7)
at next (/app/node_modules/mocha/lib/runner.js:517:10)
at Runner.runTests (/app/node_modules/mocha/lib/runner.js:556:3)
at /app/node_modules/mocha/lib/runner.js:637:10
at next (/app/node_modules/mocha/lib/runner.js:283:14)
at Immediate._onImmediate (/app/node_modules/mocha/lib/runner.js:319:5)
at processImmediate [as _immediateCallback] (timers.js:383:17)
npm ERR! Test failed. See above for more details.
Can anyone help to fix this issue?
The issues can be resolved by updating your mocha to the latest version probably to v3 or above and allure reporter too. If the issue still persists regarding TypeError: test.currentRetry is not a function , please replace the line of code
if (!test.currentRetry()) {
with the following
if (typeof test.currentRetry !== "function" || !test.currentRetry()) {
My tests run fine in my OS X environment, but when I run them on my ubuntu (EC2) server, the tests fail with:
✖ 1 of 40 tests failed:
1) AccountController "before each" hook:
Error: done() invoked with non-Error: [object Object]
at CompoundServer.<anonymous> (/usr/lib/node_modules/mocha/lib/runnable.js:198:38)
at CompoundServer.EventEmitter.emit (events.js:95:17)
at CompoundServer.initCompound (/home/ubuntu/TeamCity/buildAgent/work/1d2dd0b199edbe3f/node_modules/compound/lib/compound.js:133:14)
at CompoundServer.initCompoundServer [as init] (/home/ubuntu/TeamCity/buildAgent/work/1d2dd0b199edbe3f/node_modules/compound/lib/server/compound.js:53:29)
at /home/ubuntu/TeamCity/buildAgent/work/1d2dd0b199edbe3f/node_modules/compound/lib/compound.js:62:18
at process._tickCallback (node.js:415:13)
All i'm doing is running mocha test/*. Could this possibly be caused by a difference in compoundjs or node.js? On my mac where it is working i'm on v0.8.22, on the ubuntu server it's v0.10.5. Likewise compound version on ubuntu is 1.1.7-1, while on mac (working) is 1.1.6.
Looks like an issue with the app being generated by a previous version of compound. Changing this line on my generated test
compound.on('ready', done);
to
compound.on('ready', function() {
done();
});
Fixed the problem.