Skip to content

Commit

Permalink
Fix tests and other cases for request scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Jun 13, 2017
1 parent 4c5f488 commit 7df1e30
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 49 deletions.
22 changes: 7 additions & 15 deletions Source/Scene/Cesium3DTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,18 +410,6 @@ define([
}
},

/**
* The server that will take the request for the tile's content.
*
* @readonly
* @private
*/
serverKey : {
get : function() {
return this._serverKey;
}
},

/**
* Determines if the tile has available content to render. <code>true</code> if the tile's
* content is ready or if it has expired content that renders while new content loads; otherwise,
Expand Down Expand Up @@ -601,6 +589,7 @@ define([
*/
Cesium3DTile.prototype.requestContent = function() {
var that = this;
var tileset = this._tileset;

if (this.hasEmptyContent) {
return false;
Expand All @@ -618,7 +607,8 @@ define([
throttle : true,
throttleByServer : true,
type : RequestType.TILES3D,
priorityFunction : createPriorityFunction(this)
priorityFunction : createPriorityFunction(this),
serverKey : this._serverKey
});

var promise = loadArrayBuffer(url, undefined, request);
Expand Down Expand Up @@ -650,11 +640,11 @@ define([
var content;

if (defined(contentFactory)) {
content = contentFactory(that._tileset, that, that._contentUrl, arrayBuffer, 0);
content = contentFactory(tileset, that, that._contentUrl, arrayBuffer, 0);
that.hasRenderableContent = true;
} else {
// The content may be json instead
content = Cesium3DTileContentFactory.json(that._tileset, that, that._contentUrl, arrayBuffer, 0);
content = Cesium3DTileContentFactory.json(tileset, that, that._contentUrl, arrayBuffer, 0);
that.hasTilesetContent = true;
}

Expand All @@ -680,6 +670,8 @@ define([
if (request.state === RequestState.CANCELLED) {
// Cancelled due to low priority - try again later.
that._contentState = contentState;
--tileset.statistics.numberOfPendingRequests;
++tileset.statistics.numberOfAttemptedRequests;
return;
}
contentFailedFunction(error);
Expand Down
2 changes: 1 addition & 1 deletion Source/Scene/Cesium3DTileStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ define([

var promise;
if (typeof style === 'string') {
promise = RequestScheduler.request(style, loadJson);
promise = loadJson(style);
} else {
promise = when.resolve(style);
}
Expand Down
47 changes: 14 additions & 33 deletions Specs/Scene/Cesium3DTilesetSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ defineSuite([
});

beforeEach(function() {
RequestScheduler.clearForSpecs();
scene.morphTo3D(0.0);

var camera = scene.camera;
Expand All @@ -147,11 +148,6 @@ defineSuite([

afterEach(function() {
scene.primitives.removeAll();

// Wait for any pending requests to complete before ending each test
return pollToPromise(function() {
return RequestScheduler.getNumberOfAvailableRequests() === RequestScheduler.maximumRequests;
});
});

function setZoom(distance) {
Expand Down Expand Up @@ -302,12 +298,13 @@ defineSuite([
});

it('passes version in query string to all external resources', function() {
//Spy on loadWithXhr so we can verify requested urls
// Spy on loadWithXhr so we can verify requested urls
spyOn(loadWithXhr, 'load').and.callThrough();

var queryParams = '?a=1&b=boy';
var queryParamsWithVersion = '?a=1&b=boy&v=1.2.3';
return Cesium3DTilesTester.loadTileset(scene, tilesetWithExternalResourcesUrl + queryParams).then(function(tileset) {
console.log('loaded tileset');
var calls = loadWithXhr.load.calls.all();
var callsLength = calls.length;
for (var i = 0; i < callsLength; ++i) {
Expand Down Expand Up @@ -1127,18 +1124,6 @@ defineSuite([
});
});

it('replacement and additive refinement', function() {
// A
// A R (not rendered)
// R A R A
//
return Cesium3DTilesTester.loadTileset(scene, tilesetRefinementMix).then(function(tileset) {
var statistics = tileset._statistics;
expect(statistics.visited).toEqual(7);
expect(statistics.numberOfCommands).toEqual(6);
});
});

it('loads tileset with external tileset.json', function() {
// Set view so that no tiles are loaded initially
viewNothing();
Expand Down Expand Up @@ -1539,23 +1524,21 @@ defineSuite([

it('does not request tiles when the request scheduler is full', function() {
viewRootOnly(); // Root tiles are loaded initially
var options = {
skipLevelOfDetail : false
};
return Cesium3DTilesTester.loadTileset(scene, tilesetUrl, options).then(function(tileset) {
// Try to load 4 children. Only 3 requests will go through, 1 will be attempted.
var oldMaximumRequestsPerServer = RequestScheduler.maximumRequestsPerServer;
RequestScheduler.maximumRequestsPerServer = 3;

var promises = [
// skipLevelOfDetails loads a base level of content first
Cesium3DTilesTester.loadTileset(scene, tilesetUrl, {skipLevelOfDetail: false}),
Cesium3DTilesTester.loadTileset(scene, tilesetUrl, {skipLevelOfDetail: false})
];

return when.all(promises, function(tilesets) {
// Root tiles are ready, now zoom in to request child tiles
viewAllTiles();
scene.renderForSpecs();

// Maximum of 6 requests allowed. Expect the first tileset to use four,
// and the second tileset to use the remaining two
expect(tilesets[0]._statistics.numberOfPendingRequests).toEqual(4);
expect(tilesets[1]._statistics.numberOfPendingRequests).toEqual(2);
expect(RequestScheduler.hasAvailableRequestsByServer(tilesets[0]._url)).toEqual(false);
expect(tileset._statistics.numberOfPendingRequests).toEqual(3);
expect(tileset._statistics.numberOfAttemptedRequests).toEqual(1);

RequestScheduler.maximumRequestsPerServer = oldMaximumRequestsPerServer;
});
});

Expand Down Expand Up @@ -1654,7 +1637,6 @@ defineSuite([
}).otherwise(function(error) {
// Expect the root to not have added any children from the external tileset.json
expect(root.children.length).toEqual(0);
expect(RequestScheduler.getNumberOfAvailableRequests()).toEqual(RequestScheduler.maximumRequests);
});
});
});
Expand All @@ -1673,7 +1655,6 @@ defineSuite([
fail('should not resolve');
}).otherwise(function(error) {
expect(root._contentState).toBe(Cesium3DTileContentState.FAILED);
expect(RequestScheduler.getNumberOfAvailableRequests()).toEqual(RequestScheduler.maximumRequests);
});
});
});
Expand Down

0 comments on commit 7df1e30

Please sign in to comment.