How to change module timeout in Require.js? - requirejs

When I am on slow mobile broadband I sometimes get:
Uncaught Error: Load timeout for modules: goog!maps,3,other_params:sensor=false_unnormalized2,goog!maps,3,other_params:sensor=false,async!http://www.google.com/jsapi
I would like to raise the timeout for similar users as me sometimes using mbb.

See waitSeconds config value from RequireJS docs:
http://requirejs.org/docs/api.html#config-waitSeconds
Per the docs, the default is 7 seconds. You can set it in your require.config call like this:
require.config( {
waitSeconds : 30,
paths : {
//etc..
},

Related

Configure jest timeout once for all tests

According to the docs one can increase the default async timeout from 5000ms using the jest-object
More specifically, by using the jestsettimeouttimeout
The issue I am facing is I am running a series of tests against an API that is very slow, 5-15 second response times, configuring this jest object at the top of each test is painfully annoying.
Is it possible to declare these settings once before all test files are run?
Jest offers a testTimeout configuration option you can add to your package.json:
"jest": {
"testTimeout": 15000,
}
OK, putting bits together:
Option "setupTestFrameworkScriptFile" was replaced by configuration "setupFilesAfterEnv", which supports multiple paths
https://jestjs.io/docs/en/jest-object#jestsettimeouttimeout
https://jestjs.io/docs/en/jest-object#jestdisableautomock
The Jest search box doesn't actually return anything when you search for: setupFilesAfterEnv
And docs talk about: setupTestFrameworkScriptFile (which also doesn't return anything on the search:/ )
Anyway, the docs leave you scratching your head but this works:
jest.config.js:
module.exports = {
setupFilesAfterEnv: ['./setup.js'],
setup.js:
jest.setTimeout(10000); // in milliseconds
The jest folks should make it easier to find this information.
Use testTimeout. In yourjest.config.js (or similar), add the following:
export SECONDS = 1000;
module.exports = {
testTimeout: 60 * SECONDS
}
If you are working with react and initializing you app using create-react-app, then under your src/ directory you should have a file named setupTests.js. Here you can setup a global timeout for all of your tests just by insert this line after the import statement for #testing-libary
jest.setTimeout(15000); // in milliseconds

increase timeout when running against remote grid

when running a test locally it succeeds, but when configuring a remote grid, it fails with
1) Scenario: Login - features/api.feature:10
Step: When he enters his credentials - features/api.feature:13
Step Definition: node_modules/serenity-js/src/serenity-cucumber/webdriver_synchroniser.ts:46
Message:
function timed out after 5000 milliseconds
How can I increase the timeout value?
Thanks & Ciao
Stefan
Hi Stefan and thanks for giving Serenity/JS a try!
You have a couple of options here, depending on what is timing out.
As it's Protractor that's in charge of the timeouts, you'll need to look into your protractor.conf.js file.
Let's assume that your protractor.conf.js file looks more or less like the snippet below. I omit the Serenity/JS and Cucumber.js config for brevity as they're described at serenity-js.org:
exports.config = {
baseUrl: 'http://your.webapp.com',
// Serenity/JS config
framework: ...
specs: [ 'features/**/*.feature' ],
cucumberOpts: {
// ...
},
};
0. Increasing the overall timeout
To start with, you might want to increase the overall timeout of all the tests (for Protractor 5.0.0 the default value is set to 11s).
To do this, add the allScriptsTimeout entry to your config:
exports.config = {
allScriptsTimeout: <appropriate_timeout_in_millis>
// ... rest of the config file
}
1. Loading the page
If the webapp under test is slow to load, you can tweak the getPageTimeout property (default set to 10s):
exports.config = {
getPageTimeout: <appropriate_timeout_in_millis>
// ... rest of the config file
}
2. A specific Cucumber step
If a specific Cucumber step is timing out (which is most likely the case here, as Cucumber.js sets the default value of the cucumber step timeout to 5s), you can increase the timeout by changing the step definition (value in millis):
this.Given(/^When he enters his credentials$/, { timeout: 10 * 1000 }, () => {
return stage.theActorInTheSpotlight().attemptsTo(
Login.withTheirCredentials()
);
});
Please note that in the above answer I'm assuming that you're using Serenity/JS with Cucumber to test an Angular app. If you're using a different web framework (like React), the test might also time out when Protractor is waiting for Angular to load.
If this describes your scenario, you might want to ignoreSynchronization:
exports.config = {
onPrepare: function() {
browser.ignoreSynchronization = false;
}
// ... rest of the config file
}
To find out more, check out the Protractor documentation and the already mentioned Cucumber docs. I'll also add an article on serenity-js.org shortly to describe the different options so everything is in one place :-)
Hope this helps!
Jan

sails js cannot change timeout load hook, for bootstrap

Hello i have some problem with the bootstrap of sails, i need run a function that take approximately a minute in finished, before sails initialize, so tried do, in the bootstrap hook, but i got this error:
warn: Bootstrap is taking unusually long to execute its callback (2000 milliseconds).
Perhaps you forgot to call it? The callback is the first argument of the function, `cb`.
and searching in internet a the solution of the people was that, i have to create:
config/hookTimeout.js
and put inside :
module.exports.hookTimeout = {
hookTimeout:120000
}
to override the time of load, but still i get the same error, but i figurethat the other hooks had the hookTimeout = 120000, just the bootstrap hook dont.
The field name is bootstrapTimeout instead of hookTimeout (see here for more details).
And your config file (with a name as you like) should be as follows (nothing after module.exports):
module.exports = {
bootstrapTimeout: 60000, // in millis
};
Check if you call callback in the bootstrap file.
The simples version of config/bootstrap.js should be like next:
module.exports.bootstrap = function(cb) {
cb();
};

How to call external function in background tasks in arangodb

I have a functionality fully working and I want to call this every 30 min from background task. But It is not calling and throwing error as 'undefined'.
app.js
function hourly() { require("console"); console.log('I am running');}
controller.get('/testOnce', function(req, res) {
var tasks = require("org/arangodb/tasks");
tasks.register({
id : "Test",
name : "Testing background task",
period : 5,
command : "hourly()"
});
});
I tried defining hourly in a separate js and then calling that with 'require' But this throws cannot locate module 'myjob'
myjob.js
function hourly() { require("console"); console.log('I am running');
app.js
controller.get('/testOnce', function(req, res) {
var tasks = require("org/arangodb/tasks");
tasks.register({
id : "Test",
name : "Testing background task",
period : 5,
command : "var job = require('myjob');"
});
});
The contents of the command attribute cannot refer to variables defined in other scopes. For example, in the app.js variant you're using a variable named hourly which may not be present anymore when the command gets executed.
In the simple case of just logging something, the app.js variant could be made working if its command parameter is changed to the following (which won't require any variables):
var tasks = require("org/arangodb/tasks");
tasks.register({
period : 5,
command : "require('console').log('I am running from inline command');"
});
The variant that defines the job function in a separate file (named myjob.js) can be made working by making the function available via an export of that module:
function hourly() {
require("console").log('I am running from myjob.js');
}
exports.hourly = hourly;
This is because a require() will only expose what the module exported. In the above case the module will expose a function named hourly, which can now be invoked from a background task as follows:
var tasks = require("org/arangodb/tasks");
tasks.register({
period : 5,
command : "require('myjob').hourly();"
});
Please note that in order for this to work, the file myjob.js needs to be located in the module search path. IIRC that is js/node by default. Also note that this directory already includes the bundled modules and may change on ArangoDB updates.
If the regular command is to be executed from within a Foxx route, then using Foxx queues might also be an option as they should allow putting the script with the job function inside the application directory. However, I have not tried this yet.
The "Foxx way" of solving this would be using the queue and a script-based job (introduced in 2.6).
I've covered this in the last Foxx webinar and am working on a blog post and cookbook recipe.
The problem with doing it this way is that Foxx jobs can not be periodic in 2.6. The feature is planned for 2.7 but with 2.6 only just having been released, you probably won't be able to use it any time soon.
Personally I would recommend using an external scheduler and invoking the Foxx script from there (via the foxx-manager CLI or the HTTP API).

node.js - request - How to "emitter.setMaxListeners()"?

When I do a GET on a certain URI using the node.js 'request' module;
var options = {uri:"aURI", headers:headerData};
request.get(options, function (error, response, body) {
}
The error message is:
[Error: Exceeded maxRedirects. Probably stuck in a redirect loop.]
and there is also the following message:
"(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit."
How do I setMaxListeners?
I strongly advice NOT to use the code:
process.setMaxListeners(0);
The warning is not there without reason. Most of the time, it is because there is an error hidden in your code. Removing the limit removes the warning, but not its cause, and prevents you from being warned of a source of resource leakage.
If you hit the limit for a legitimate reason, put a reasonable value in the function (the default is 10).
Also, to change the default, it is not necessary to mess with the EventEmitter prototype. you can set the value of defaultMaxListeners attribute like so:
require('events').EventEmitter.defaultMaxListeners = 15;
I use the code to increase the default limit globally:
require('events').EventEmitter.prototype._maxListeners = 100;
This is how I solved the problem:
In main.js of the 'request' module I added one line:
Request.prototype.request = function () {
var self = this
self.setMaxListeners(0); // Added line
This defines unlimited listeners http://nodejs.org/docs/v0.4.7/api/events.html#emitter.setMaxListeners
In my code I set the 'maxRedirects' value explicitly:
var options = {uri:headingUri, headers:headerData, maxRedirects:100};
Although adding something to nodejs module is possible, it seems to be not the best way (if you try to run your code on other computer, the program will crash with the same error, obviously).
I would rather set max listeners number in your own code:
var options = {uri:headingUri, headers:headerData, maxRedirects:100};
request.setMaxListeners(0);
request.get(options, function (error, response, body) {
}
Try to use:
require('events').EventEmitter.defaultMaxListeners = Infinity;
this is Extension to #FĂ©lix Brunet answer
Reason - there is code hidden in your app
How to find -
Strip/comment code and execute until you reach error
check log file
Eg - In my case i created 30 instances of winston log Unknowingly and it started giving error
Note : if u supress this error , it will come again afetr 3..4 days
It also happened to me
I use this code and it worked
require('events').EventEmitter.defaultMaxListeners = infinity;
Try it out. It may help
Thanks

Resources