mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-24 06:06:09 +03:00
Merge pull request #1192 from UCLALibrary/timeout-configuration
Enable configuration of ImageJob timeout
This commit is contained in:
commit
dc70acec55
@ -45,6 +45,7 @@
|
|||||||
* @param {String} [options.crossOriginPolicy] - CORS policy to use for downloads
|
* @param {String} [options.crossOriginPolicy] - CORS policy to use for downloads
|
||||||
* @param {Function} [options.callback] - Called once image has been downloaded.
|
* @param {Function} [options.callback] - Called once image has been downloaded.
|
||||||
* @param {Function} [options.abort] - Called when this image job is aborted.
|
* @param {Function} [options.abort] - Called when this image job is aborted.
|
||||||
|
* @param {Number} [options.timeout] - The max number of milliseconds that this image job may take to complete.
|
||||||
*/
|
*/
|
||||||
function ImageJob (options) {
|
function ImageJob (options) {
|
||||||
|
|
||||||
@ -171,11 +172,13 @@ ImageJob.prototype = {
|
|||||||
* You generally won't have to interact with the ImageLoader directly.
|
* You generally won't have to interact with the ImageLoader directly.
|
||||||
* @param {Object} options - Options for this ImageLoader.
|
* @param {Object} options - Options for this ImageLoader.
|
||||||
* @param {Number} [options.jobLimit] - The number of concurrent image requests. See imageLoaderLimit in {@link OpenSeadragon.Options} for details.
|
* @param {Number} [options.jobLimit] - The number of concurrent image requests. See imageLoaderLimit in {@link OpenSeadragon.Options} for details.
|
||||||
|
* @param {Number} [options.timeout] - The max number of milliseconds that an image job may take to complete.
|
||||||
*/
|
*/
|
||||||
$.ImageLoader = function(options) {
|
$.ImageLoader = function(options) {
|
||||||
|
|
||||||
$.extend(true, this, {
|
$.extend(true, this, {
|
||||||
jobLimit: $.DEFAULT_SETTINGS.imageLoaderLimit,
|
jobLimit: $.DEFAULT_SETTINGS.imageLoaderLimit,
|
||||||
|
timeout: $.DEFAULT_SETTINGS.timeout,
|
||||||
jobQueue: [],
|
jobQueue: [],
|
||||||
jobsInProgress: 0
|
jobsInProgress: 0
|
||||||
}, options);
|
}, options);
|
||||||
@ -210,7 +213,8 @@ $.ImageLoader.prototype = {
|
|||||||
crossOriginPolicy: options.crossOriginPolicy,
|
crossOriginPolicy: options.crossOriginPolicy,
|
||||||
ajaxWithCredentials: options.ajaxWithCredentials,
|
ajaxWithCredentials: options.ajaxWithCredentials,
|
||||||
callback: complete,
|
callback: complete,
|
||||||
abort: options.abort
|
abort: options.abort,
|
||||||
|
timeout: this.timeout
|
||||||
},
|
},
|
||||||
newJob = new ImageJob(jobOptions);
|
newJob = new ImageJob(jobOptions);
|
||||||
|
|
||||||
|
@ -411,6 +411,7 @@
|
|||||||
* The max number of images we should keep in memory (per drawer).
|
* The max number of images we should keep in memory (per drawer).
|
||||||
*
|
*
|
||||||
* @property {Number} [timeout=30000]
|
* @property {Number} [timeout=30000]
|
||||||
|
* The max number of milliseconds that an image job may take to complete.
|
||||||
*
|
*
|
||||||
* @property {Boolean} [useCanvas=true]
|
* @property {Boolean} [useCanvas=true]
|
||||||
* Set to false to not use an HTML canvas element for image rendering even if canvas is supported.
|
* Set to false to not use an HTML canvas element for image rendering even if canvas is supported.
|
||||||
|
@ -370,7 +370,8 @@ $.Viewer = function( options ) {
|
|||||||
|
|
||||||
// Create the image loader
|
// Create the image loader
|
||||||
this.imageLoader = new $.ImageLoader({
|
this.imageLoader = new $.ImageLoader({
|
||||||
jobLimit: this.imageLoaderLimit
|
jobLimit: this.imageLoaderLimit,
|
||||||
|
timeout: options.timeout
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create the tile cache
|
// Create the tile cache
|
||||||
|
@ -81,6 +81,7 @@
|
|||||||
<script src="/test/modules/spring.js"></script>
|
<script src="/test/modules/spring.js"></script>
|
||||||
<script src="/test/modules/rectangle.js"></script>
|
<script src="/test/modules/rectangle.js"></script>
|
||||||
<script src="/test/modules/ajax-tiles.js"></script>
|
<script src="/test/modules/ajax-tiles.js"></script>
|
||||||
|
<script src="/test/modules/imageloader.js"></script>
|
||||||
<!-- The navigator tests are the slowest (for now; hopefully they can be sped up)
|
<!-- The navigator tests are the slowest (for now; hopefully they can be sped up)
|
||||||
so we put them last. -->
|
so we put them last. -->
|
||||||
<script src="/test/modules/navigator.js"></script>
|
<script src="/test/modules/navigator.js"></script>
|
||||||
|
88
test/modules/imageloader.js
Normal file
88
test/modules/imageloader.js
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
/* global module, asyncTest, $, ok, equal, notEqual, start, test, Util, testLog */
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
var viewer,
|
||||||
|
baseOptions = {
|
||||||
|
id: 'example',
|
||||||
|
prefixUrl: '/build/openseadragon/images/',
|
||||||
|
springStiffness: 100 // Faster animation = faster tests
|
||||||
|
};
|
||||||
|
|
||||||
|
module('ImageLoader', {
|
||||||
|
setup: function () {
|
||||||
|
var example = $('<div id="example"></div>').appendTo("#qunit-fixture");
|
||||||
|
|
||||||
|
testLog.reset();
|
||||||
|
},
|
||||||
|
teardown: function () {
|
||||||
|
if (viewer && viewer.close) {
|
||||||
|
viewer.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
viewer = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// ----------
|
||||||
|
|
||||||
|
test('Default timeout', function() {
|
||||||
|
var actual,
|
||||||
|
expected = OpenSeadragon.DEFAULT_SETTINGS.timeout,
|
||||||
|
message,
|
||||||
|
options = OpenSeadragon.extend(true, baseOptions, {
|
||||||
|
imageLoaderLimit: 1
|
||||||
|
}),
|
||||||
|
viewer = OpenSeadragon(options),
|
||||||
|
imageLoader = viewer.imageLoader;
|
||||||
|
|
||||||
|
message = 'ImageLoader timeout should be set to the default value of ' + expected + ' when none is specified';
|
||||||
|
actual = imageLoader.timeout;
|
||||||
|
equal(actual, expected, message);
|
||||||
|
|
||||||
|
// Manually seize the ImageLoader
|
||||||
|
imageLoader.jobsInProgress = imageLoader.jobLimit;
|
||||||
|
imageLoader.addJob({
|
||||||
|
src: 'test',
|
||||||
|
loadWithAjax: false,
|
||||||
|
crossOriginPolicy: 'test',
|
||||||
|
ajaxWithCredentials: false,
|
||||||
|
abort: function() {}
|
||||||
|
});
|
||||||
|
|
||||||
|
message = 'ImageJob should inherit the ImageLoader timeout value';
|
||||||
|
actual = imageLoader.jobQueue.shift().timeout;
|
||||||
|
equal(actual, expected, message);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ----------
|
||||||
|
|
||||||
|
test('Configure timeout', function() {
|
||||||
|
var actual,
|
||||||
|
expected = 123456,
|
||||||
|
message,
|
||||||
|
options = OpenSeadragon.extend(true, baseOptions, {
|
||||||
|
imageLoaderLimit: 1,
|
||||||
|
timeout: expected
|
||||||
|
}),
|
||||||
|
viewer = OpenSeadragon(options),
|
||||||
|
imageLoader = viewer.imageLoader;
|
||||||
|
|
||||||
|
message = 'ImageLoader timeout should be configurable';
|
||||||
|
actual = imageLoader.timeout;
|
||||||
|
equal(actual, expected, message);
|
||||||
|
|
||||||
|
imageLoader.jobsInProgress = imageLoader.jobLimit;
|
||||||
|
imageLoader.addJob({
|
||||||
|
src: 'test',
|
||||||
|
loadWithAjax: false,
|
||||||
|
crossOriginPolicy: 'test',
|
||||||
|
ajaxWithCredentials: false,
|
||||||
|
abort: function() {}
|
||||||
|
});
|
||||||
|
|
||||||
|
message = 'ImageJob should inherit the ImageLoader timeout value';
|
||||||
|
actual = imageLoader.jobQueue.shift().timeout;
|
||||||
|
equal(actual, expected, message);
|
||||||
|
});
|
||||||
|
|
||||||
|
})();
|
@ -43,6 +43,7 @@
|
|||||||
<script src="/test/modules/spring.js"></script>
|
<script src="/test/modules/spring.js"></script>
|
||||||
<script src="/test/modules/rectangle.js"></script>
|
<script src="/test/modules/rectangle.js"></script>
|
||||||
<script src="/test/modules/ajax-tiles.js"></script>
|
<script src="/test/modules/ajax-tiles.js"></script>
|
||||||
|
<script src="/test/modules/imageloader.js"></script>
|
||||||
<!-- The navigator tests are the slowest (for now; hopefully they can be sped up)
|
<!-- The navigator tests are the slowest (for now; hopefully they can be sped up)
|
||||||
so we put them last. -->
|
so we put them last. -->
|
||||||
<script src="/test/modules/navigator.js"></script>
|
<script src="/test/modules/navigator.js"></script>
|
||||||
|
Loading…
Reference in New Issue
Block a user