Reputation: 1110
I'm trying to mock a timeout from a webpage so that I can implement a "deal with timeout" feature.
Basically what I need is a URL of something that does not reply within X seconds.
Thanks in advance
Here's the code I have:
var req = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance();
req.overrideMimeType('text/plain; charset=utf-8');
req.open("GET", configurationURL, false);
req.variable = specificConfigurationURLTerminator;
setTimeout(function() {
alert("aborting");
req.abort();
}, this.configurationRetrievalTimeout);
req.send(null);
Upvotes: 15
Views: 8452
Reputation: 1562
while www.google.com:81
trick is a good one, it didn't work for me while trying to timeout a SOAPConnection
, which might be irrelevant.
I happened to have node.js
installed anyway, and the following did a good job:
First, save the following as test.js
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
//res.statusCode = 200;
//res.setHeader('Content-Type', 'text/plain');
//res.end('Hello World');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
Then execute the following in command prompt:
node test.js
And visit http://localhost:3000
to hang indefinitely
Upvotes: 0
Reputation: 1110
Guys thank you so much for your prompt replies. I've found what I was looking for:
basically doesn't respond not even with an error =) exactly what I need to trigger a timeout
Upvotes: 37
Reputation: 2540
use .delay(duration) jquery function. duration will be in milisecond. ex- $('div').delay(1500);
Upvotes: 0