Skip to content

Commit

Permalink
Fix failed assertion tearing down offline tests
Browse files Browse the repository at this point in the history
Discovered while working on #894

Change-Id: Icf74cd4bf804df0b055033f9c1113971e1644202
  • Loading branch information
joeyparrish committed Jun 22, 2017
1 parent bbdc0ba commit 1eb5a41
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/offline/db_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ shaka.offline.DBEngine.prototype.createTransaction_ = function(storeName,
type,
action) {

goog.asserts.assert(this.db_, 'Must not be destroyed');
goog.asserts.assert(this.db_, 'DBEngine must not be destroyed');
goog.asserts.assert(type == 'readonly' || type == 'readwrite',
'Type must be "readonly" or "readwrite"');

Expand Down
10 changes: 8 additions & 2 deletions lib/offline/download_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,12 @@ shaka.offline.DownloadManager.prototype.destroy = function() {
var storage = this.storageEngine_;
var segments = this.storedSegments_;
var p = this.promise_ || Promise.resolve();
p = p.then(function() { return storage.removeKeys('segment', segments); });

// Don't try to remove segments if there are none. That may trigger an error
// in storage if the DB connection was never created.
if (segments.length) {
p = p.then(function() { return storage.removeKeys('segment', segments); });
}

// Don't destroy() storageEngine since it is owned by Storage.

Expand Down Expand Up @@ -229,7 +234,8 @@ shaka.offline.DownloadManager.prototype.downloadAndStore = function(manifest) {
* @private
*/
shaka.offline.DownloadManager.prototype.downloadSegment_ = function(segment) {
goog.asserts.assert(this.retryParams_, 'Must not be destroyed');
goog.asserts.assert(this.retryParams_,
'DownloadManager must not be destroyed');
var type = shaka.net.NetworkingEngine.RequestType.SEGMENT;
var request =
shaka.net.NetworkingEngine.makeRequest(segment.uris, this.retryParams_);
Expand Down
2 changes: 1 addition & 1 deletion lib/offline/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ shaka.offline.Storage.prototype.destroy = function() {
* @export
*/
shaka.offline.Storage.prototype.configure = function(config) {
goog.asserts.assert(this.config_, 'Must not be destroyed');
goog.asserts.assert(this.config_, 'Storage must not be destroyed');
shaka.util.ConfigUtils.mergeConfigObjects(
this.config_, config, this.defaultConfig_(), {}, '');
};
Expand Down

0 comments on commit 1eb5a41

Please sign in to comment.