Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed May 8, 2017
1 parent 11bede6 commit b5c719d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
1 change: 1 addition & 0 deletions Source/Scene/Cesium3DTileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,7 @@ define([
node = node.next;
unloadTileFromCache(tileset, tile);
tile.unloadContent();
totalMemoryUsageInBytes = tileset.totalMemoryUsageInBytes;
}
}

Expand Down
15 changes: 7 additions & 8 deletions Source/Scene/Cesium3DTilesetTraversal.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ define([
return;
}

if (root.contentUnloaded) {
loadTile(root, frameState);
return;
}
loadTile(root, frameState);

if (!tileset.skipLODs) {
// just execute base traversal and add tiles to _desiredTiles
Expand Down Expand Up @@ -336,17 +333,18 @@ define([
tileset._desiredTiles.push(tile);
}

// Stop traversal on the subtree since it will be destroyed
if (tile.hasTilesetContent && tile.contentExpired) {
return false;
}

// stop traversal when we've attained the desired level of error
if (tile._screenSpaceError <= baseScreenSpaceError && !tile.hasTilesetContent) {
// update children so the leaf handler can check if any are visible for the children union bound optimization
updateChildren(tileset, tile, frameState);
return false;
}

if (tile.hasTilesetContent && tile.contentExpired) {
return false;
}

var childrenVisibility = updateChildren(tileset, tile, frameState);
var showAdditive = tile.refine === Cesium3DTileRefine.ADD;
var showReplacement = tile.refine === Cesium3DTileRefine.REPLACE && (childrenVisibility & Cesium3DTileChildrenVisibility.VISIBLE_IN_REQUEST_VOLUME) !== 0;
Expand Down Expand Up @@ -493,6 +491,7 @@ define([
var tileset = this.tileset;
var maximumScreenSpaceError = tileset._maximumScreenSpaceError;

// Stop traversal on the subtree since it will be destroyed
if (tile.hasTilesetContent && tile.contentExpired) {
return emptyArray;
}
Expand Down
25 changes: 10 additions & 15 deletions Specs/Scene/Cesium3DTilesetSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,15 +416,7 @@ defineSuite([
expect(stats.numberProcessing).toEqual(0);

return Cesium3DTilesTester.waitForReady(scene, tileset).then(function() {
// Check that root tile is requested
expect(stats.visited).toEqual(0);
expect(stats.numberOfCommands).toEqual(0);
expect(stats.numberOfPendingRequests).toEqual(1);
expect(stats.numberProcessing).toEqual(0);

// Update and check that child tiles are now requested
scene.renderForSpecs();

// Check that root and children are requested
expect(stats.visited).toEqual(5);
expect(stats.numberOfCommands).toEqual(0);
expect(stats.numberOfPendingRequests).toEqual(5);
Expand Down Expand Up @@ -1613,6 +1605,7 @@ defineSuite([
});

it('destroys before tile finishes loading', function() {
viewRootOnly();
var tileset = scene.primitives.add(new Cesium3DTileset({
url : tilesetUrl
}));
Expand Down Expand Up @@ -2547,7 +2540,7 @@ defineSuite([
RequestScheduler.maximumRequests = originalMaxmimumRequests;
expiredContent = tile._expiredContent;
expect(tile.contentExpired).toBe(true);
expect(tile.contentAvailable).toBe(true); // Expire content now exists
expect(tile.contentAvailable).toBe(true); // Expired content now exists
expect(expiredContent).toBeDefined();

// Expired content renders while new content loads in
Expand Down Expand Up @@ -2607,10 +2600,9 @@ defineSuite([
return Cesium3DTilesTester.loadTileset(scene, tilesetSubtreeExpirationUrl).then(function(tileset) {
// Intercept the request and load a subtree with one less child. Still want to make an actual request to simulate
// real use cases instead of immediately returning a pre-created array buffer.
var originalLoad = loadWithXhr.load;
spyOn(loadWithXhr, 'load').and.callFake(function(url, responseType, method, data, headers, deferred, overrideMimeType) {
var newDeferred = when.defer();
originalLoad(tilesetSubtreeUrl, responseType, method, data, headers, newDeferred, overrideMimeType);
loadWithXhr.defaultLoad(tilesetSubtreeUrl, responseType, method, data, headers, newDeferred, overrideMimeType);
newDeferred.promise.then(function(arrayBuffer) {
deferred.resolve(modifySubtreeBuffer(arrayBuffer));
});
Expand All @@ -2634,15 +2626,16 @@ defineSuite([
tileset.tileUnload.addEventListener(spyUpdate);

// Tiles in the subtree are removed from the cache and destroyed.
scene.renderForSpecs();
scene.renderForSpecs(); // Becomes expired
scene.renderForSpecs(); // Makes request
expect(subtreeRoot.children).toEqual([]);
for (var i = 0; i < childrenLength; ++i) {
expect(subtreeChildren[0].isDestroyed()).toBe(true);
}
expect(spyUpdate.calls.count()).toEqual(4);

// Remove the spy so new tiles load in normally
loadWithXhr.load = originalLoad;
loadWithXhr.load = loadWithXhr.defaultLoad;

// Wait for the new tileset content to come in with one less leaf
return pollToPromise(function() {
Expand All @@ -2668,12 +2661,14 @@ defineSuite([
// Trigger expiration to happen next frame
tile.expireDate = JulianDate.addSeconds(JulianDate.now(), -1.0, new JulianDate());

// After update the tile is expired
scene.renderForSpecs();

// Make request (it will fail)
scene.renderForSpecs();

// Render scene
scene.renderForSpecs();

expect(tile._contentState).toBe(Cesium3DTileContentState.FAILED);
expect(stats.numberOfCommands).toBe(0);
expect(stats.numberTotal).toBe(1);
Expand Down

0 comments on commit b5c719d

Please sign in to comment.