1

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...

Paolo
  • 15,233
  • 27
  • 70
  • 91

1 Answers1

1

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.

Dave
  • 3,280
  • 2
  • 22
  • 40
  • I meant I want to test from a users point of view your web server being offline and yet their client still processing/running the javascript. Of course turning off the server running on localhost is another option, but I'd prefer to avoid that (if possible) and use a technique that let me leave the server up and selectively "miss" some requests and satisfy some others. - I'll edit my question to specify I prefer not to shut down the server. Thank you for your answer – Paolo Apr 19 '14 at 19:29
  • There's no real way to simulate that if you're all running on local host. you could try putting your wamp server etc online and accessing it via the network interface rather than localhost and then turning off your net connection. Or you could perhaps put a load tester running and limit your mysql config so the db server locks. But apart from that there's no real way to test what you want to test without shutting down your webserver. – Dave Apr 19 '14 at 22:17