Reputation: 15827
I have an interactive web page that upon user interaction makes asyncronous requests to the server (loading images, data, etc.).
As a final stage I'm implementing the JavaScript code in order to handle properly situations where the server is too busy or a network congestion occurs and a request is not satisfied.
During development both server and client (browser) run on the development machine (localhost).
To test the code I have to simulate on my local development machine those situations.
I can easily simulate a "Service Unavailable" response.
But how can I simulate a "no response at all" ?
Is placing
sleep(3600);
at the beginning of the php
that get executed when the request is made enought to achieve what I need to simulate?
Or does something still goes back to the browser?
Is there a better way to test browser-side code in poor-server-availability situations?
Edit
One option is to just shut down the server running on localhost as suggested by Dave in his answer.
I'd prefer -if possible- to avoid that.
I'd like to be able to miss some requests and satisfy some others.
The idea behind that is that the client side JavaScript code running on the browser will retry failed requests.
The server simulates unavailability for one request, the client retries, the server give the response...
Upvotes: 1
Views: 1243
Reputation: 3288
Only way you'd ever encounter those is if the javascript for your async requests was calling data/files from a server other than the server pushing out your primary pages. so if you're just running a single instance of apache for example then you'd never encounter network congestion or not available. if you are for example running apache as your primary web server and nginx on a different port as your content server then to test it its simply a case of stopping the nginx serving your content.
If you mean you want to test from a users point of view your web server being offline and yet their client still processing/running the javascript (assuming your server was online for the initial load/request) then load the page in your browser and stop your web server then wait for it to error out on the client side. Of course you'll need to restart the web server to reload your files and retest after changes.
Upvotes: 1