HTML and CSS Reference
In-Depth Information
ajax.request = stubFn();
this.xhr.complete();
Clock.tick(0);
assert(ajax.request.called);
}
And that's it. The poller now supports long polling with an optional minimal
interval between new requests to the server. The poller could be further extended to
support another option to set minimum grace period between requests, regardless
of the time any given request takes. This would increase latency, but could help a
stressed system.
13.3.2 Avoiding Cache Issues
One possible challenge with the current implementation of the poller is that of
caching. Polling is typically used when we need to stream fresh data off the server,
and having the browser cache responses is likely to cause trouble. Caching can be
controlled from the server via response headers, but sometimes we don't control
the server implementation. In the interest of making the poller as generally useful as
possible, we will extend it to add some random fuzz to the URL, which effectively
avoids caching.
To test the cache buster, we simply expect the open method of the transport
to be called with the URL including a timestamp, as seen in Listing 13.39.
Listing 13.39 Expecting poller to add cache buster to URL
"test should add cache buster to URL": function () {
var date = new Date();
var ts = date.getTime();
stubDateConstructor(date);
this.poller.url = "/url";
this.poller.start();
assertEquals("/url?" + ts, this.xhr.open.args[1]);
}
To pass this test, Listing 13.40 simply adds the date it is already recording to
the URL when making a request.
 
Search WWH ::




Custom Search