Skip to content

Commit

Permalink
#909 it can happen that nodes removed during load (missing base), tha…
Browse files Browse the repository at this point in the history
…t should be handled by the metaCache as well
  • Loading branch information
kecso committed Mar 23, 2016
1 parent cf3fd4c commit f4b1d0f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/common/core/metacachecore.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
*/

define([
'common/util/assert',
'common/core/tasync',
'common/core/constants'
], function (ASSERT, TASYNC, CONSTANTS) {
'common/util/assert',
'common/core/tasync',
'common/core/constants'
], function (ASSERT, TASYNC, CONSTANTS) {
'use strict';

var MetaCacheCore = function (innerCore, options) {
Expand Down Expand Up @@ -41,6 +41,7 @@ define([
return TASYNC.lift(metaNodes);
}, self.loadPaths(self.getHash(root), JSON.parse(JSON.stringify(paths))));
}

//</editor-fold>

//<editor-fold=Modified Methods>
Expand All @@ -50,7 +51,10 @@ define([
var i = 0;
root.metaNodes = {};
for (i = 0; i < elements.length; i += 1) {
root.metaNodes[innerCore.getPath(elements[i])] = elements[i];
// It can happen that some elements just been removed during load because of missing base.
if (elements[i]) {
root.metaNodes[innerCore.getPath(elements[i])] = elements[i];
}
}
return root;
}, loadMetaSet(root));
Expand Down
32 changes: 32 additions & 0 deletions test/common/core/metacachecore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,36 @@ describe('meta cache core', function () {
expect(core.isConnection(nonConnection)).to.equal(false);
});

it('should detect if some META element have been deleted during load', function (done) {
//core.delMember(rootNode, 'MetaAspectSet', metaPaths.pop());
var root = core.createNode({}),
itemBase = core.createNode({parent: root}),
item = core.createNode({parent: root, base: itemBase}),
itemBasePath = core.getPath(itemBase),
hash = core.getHash(root);

core.addMember(root, 'MetaAspectSet', itemBase);
core.addMember(root, 'MetaAspectSet', item);

expect(Object.keys(core.getAllMetaNodes(root))).to.have.length(2);
core.persist(root);
hash = core.getHash(root);

core.loadRoot(hash)
.then(function (root) {
var itemBase;
expect(Object.keys(core.getAllMetaNodes(root))).to.have.length(2);

itemBase = core.getAllMetaNodes(root)[itemBasePath];
core.deleteNode(itemBase,true);
core.persist(root);
hash = core.getHash(root);

return core.loadRoot(hash);
})
.then(function (root) {
expect(Object.keys(core.getAllMetaNodes(root))).to.have.length(0);
})
.nodeify(done);
});
});

0 comments on commit f4b1d0f

Please sign in to comment.