I'm currently using Mocha for testing but I seem to be running into some errors testing an app that uses Cluster.
Basically, the app exits, but then some of the workers still do things, and this causes weird output which is basically failing the "before all" hooks, even after the tests finished.
I saw this thread How to test a clustered Express app with Mocha?
but I wonder if Mocha is even the right module to test a Cluster app with. If so, can someone please point me to a tutorial on how to do it? I couldn't find any after Googling.
I am also using Express in case that complicates things.
Related
Let's say inside a Jest test I am using child-process of Node and it takes a lot of time to execute. I don't want to do that. I want Jest to execute that at all costs. Any idea how to do that?
I don't want to mock it.
Ever since I upgraded to Big Sur, I've noticed that Sophos has begun to interfere dramatically whenever I run Jest tests. CPU usage for Sophos spikes to around 400% when running even a modest Jest test program, with 71 tests currently taking 98.6 seconds to run. After the Jest process completes, Sophos goes back to sleep and no longer takes up substantial resources.
I run these tests from my terminal using Node. My hypothesis is that the problem is actually between Node and Sophos, and it's just exacerbated by the way that Jest runs its tests.
Has anyone come across this problem before, and is there anything I can do to convince Sophos to leave Node alone?
For what it's worth, the tests themselves are bog-standard JS and React unit tests, with the React tests written using React Testing Library.
I wrote some integration tests for a node app that works with Ethereum smart contracts (and thus use the contracts' state as a data storage). I am instantiating some smart contracts interfaces using web3 and in the assertion parts of the tests I am using them to check that valid information has been written to the blockchain.
However after the tests pass the mocha process is still running and I have to shut it down manually. I suspect this happens because the smart contract interfaces are basically open connections and they are not closed, I know it happens when you do the same with normal database connections (see here: Mocha hangs after execution when connecting with Mongoose).
I didn't find any disconnect or similar web3 api methods though, anyone had any similar experience with this?
Someone pointed me that there is an --exit flag that you can pass to mocha and it kills the process after all tests have finished running. This is probably a good enough solution for now.
We have a large website with express and the whole application is written in Node.JS.
When the mongo db is down our app starts hanging when you refresh the browser on home page and also in other page. This is caused because of the behaviour of the mongoose library when the mongo database goes down. the app is served from ubuntu 14.04 machines.
My question is how to test application "hangs".
What kind of tests should I perform to know that i don't have any more web app hangs. The problem is that a hang can be caused by multiple reasons and not just by the mongoose issue which i have fixed.
How can I test that?
What kind of tools and techniques are recommended?
I'm working with NodeJs from a couple of time & it was doing a really good job when there is only IO. And then I faced this challenge.
We have a game in which every time on an average 250 users play. Currently its back-end server is running on java. But now we want to convert it in NodeJs.
So we were going good until when we reached to the game engine. Where there is so many CPU-bound jobs. When a user is getting served these CPU-Bound requests, all others are getting blocked. This is really normal I know so we tested all the solutions of this problem before abandoning the project.
Used the following:
callback
thread and threadPool from node_module webWorker-threads
created separate js file for all CPU-Bound jobs and ran them in process.exec
cluster
created each thing in different module
But except process.exec & cluster all are in vain. In these two solution cluster is also too much unpredictable. Because it happened that in a worker multiple requests are assigned & in the front there is a CPU-Bound job, in that case again same issue.
Only process.exec is working good. But we have so many CPU-Bound tasks, if we do a separate file for each of them then it will be a mess.
So I want to know if it is not at all possible in NodeJs or not. Anyone of stack-overflow community faced this issue and solved it or anyone want to give any solution regarding this, a big thanks to all of them...