Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Head and tail pending notifications and tests

  • Loading branch information...
commit 5b3c9c853c202373689b5cf78bfb96ac5bff7096 1 parent 576c83d
@kpdecker kpdecker authored
View
113 tipsAndTricks/data-model-base/data-model-base-test.js
@@ -16,8 +16,10 @@ DataModelBaseTest.prototype.exec = function(assistant, cont) {
this.cancelTest,
this.failureTest,
this.headPendingTest,
+ this.headPendingInprocessTest,
this.preSeedHeadPendingTest,
this.tailPendingTest,
+ this.tailPendingInprocessTest,
this.tailPendingRemoveTest,
], 0)();
};
@@ -674,6 +676,52 @@ DataModelBaseTest.prototype.headPendingTest = function(assistant, cont) {
});
};
+DataModelBaseTest.prototype.headPendingInprocessTest = function(assistant, cont) {
+ var runCount = 0;
+ var dataModel = new DataModelTest({
+ maxCount: 10,
+ lookahead: 1
+ }),
+ expected = [
+ {
+ offset: 0,
+ limit: 4,
+ complete: false,
+ knownSize: 7,
+ loadRangeCount: 1,
+ loadRange: { offset: 0, limit: 5 },
+ results: [ 11, 12, 10, 9 ],
+ headPending: [ 11, 12 ]
+ }
+ ];
+
+ dataModel.blockTimeout = 100;
+
+ dataModel.getRange(0, 4,
+ function(offset, limit, results) {
+ verifyRange(assistant, expected[runCount++], dataModel, offset, limit, results);
+ if (runCount === 1) {
+ cont();
+ } else {
+ assistant.failure("Multiple calls made");
+ }
+ },
+ function(failure) {
+ assistant.failure("Recieved failure");
+ cont();
+ });
+
+ dataModel.refreshQueue.queue({
+ onSuccess: function() {
+ dataModel.addPending(12, false);
+ dataModel.addPending(11, false);
+
+ Mojo.Log.info("Block timeout: %j", dataModel.blockedRequests);
+ dataModel.blockTimeout = 0;
+ }
+ });
+};
+
DataModelBaseTest.prototype.preSeedHeadPendingTest = function(assistant, cont) {
var runCount = 0;
var dataModel = new DataModelTest({
@@ -810,6 +858,70 @@ DataModelBaseTest.prototype.tailPendingTest = function(assistant, cont) {
});
};
+DataModelBaseTest.prototype.tailPendingInprocessTest = function(assistant, cont) {
+ var runCount = 0;
+ var dataModel = new DataModelTest({
+ maxCount: 10,
+ lookahead: 1
+ }),
+ expected = [
+ {
+ offset: 0,
+ limit: 1,
+ complete: false,
+ knownSize: 1,
+ loadRangeCount: 0,
+ results: [ 12 ],
+ headPending: [],
+ tailPending: [ 12 ]
+ },
+ {
+ offset: 0,
+ limit: 2,
+ complete: false,
+ knownSize: 2,
+ loadRangeCount: 0,
+ results: [ 12, 11 ],
+ headPending: [],
+ tailPending: [ 12, 11 ]
+ },
+ {
+ offset: 0,
+ limit: 4,
+ complete: false,
+ knownSize: 7,
+ loadRangeCount: 1,
+ loadRange: { offset: 0, limit: 5 },
+ results: [ 10, 9, 8, 7 ],
+ headPending: []
+ }
+ ];
+
+ dataModel.blockTimeout = 100;
+
+ dataModel.getRange(0, 4,
+ function(offset, limit, results) {
+ verifyRange(assistant, expected[runCount++], dataModel, offset, limit, results);
+ if (runCount === 1) {
+ dataModel.addPending(11, true);
+ } else if (runCount === 2) {
+ dataModel.blockTimeout = 0;
+ } else if (runCount === 3) {
+ cont();
+ }
+ },
+ function(failure) {
+ assistant.failure("Recieved failure");
+ cont();
+ });
+
+ dataModel.refreshQueue.queue({
+ onSuccess: function() {
+ dataModel.addPending(12, true);
+ }
+ });
+};
+
DataModelBaseTest.prototype.tailPendingRemoveTest = function(assistant, cont) {
var runCount = 0;
var dataModel = new DataModelTest({
@@ -891,7 +1003,6 @@ DataModelBaseTest.prototype.tailPendingRemoveTest = function(assistant, cont) {
});
};
-// TODO : Pending + Refresh test
var DataModelTest = Class.create(DataModelBase, {
initialize: function($super, options) {
View
4 tipsAndTricks/data-model-base/data-model-base.js
@@ -194,6 +194,7 @@ var DataModelBase = Class.create(Observable, {
addPending: function(item, tail) {
if (tail) {
this.tailPending.push(item);
+ this.notifyPendingRequests();
} else {
this.headPending.unshift(item);
}
@@ -354,7 +355,7 @@ var DataModelBase = Class.create(Observable, {
Mojo.Log.info("Loaded %s from remote. readLimit: %d known: %d results: %d resultOffset: %d responseLen: %d", this.getCacheName(), readLimit, this.getKnownSize(), results.length, resultOffset, responseLen);
// Load the new data into the memory cache
- var spliceArgs = $A(results);
+ var spliceArgs = results.slice();
spliceArgs.unshift(readOffset+resultOffset, results.length);
this.cache.splice.apply(this.cache, spliceArgs);
@@ -417,7 +418,6 @@ var DataModelBase = Class.create(Observable, {
},
notifyPendingRequests: function() {
- // TODO : Add tests for this with pending data involved
var len = this.blockedRequests.length,
cacheLen = this.headPending.length + this.cache.length + this.tailPending.length;
for (var i = 0; i < len; i++) {
Please sign in to comment.
Something went wrong with that request. Please try again.