Skip to content

Commit

Permalink
Merge pull request #267 from silvolu/fix-datastore-regression
Browse files Browse the repository at this point in the history
fix (regression tests): make datastore queries strongly consistent
  • Loading branch information
ryanseys committed Oct 23, 2014
2 parents ce92ff6 + e633edf commit 51abc0d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 21 deletions.
12 changes: 12 additions & 0 deletions regression/data/index.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
indexes:

- kind: Character
ancestor: yes
properties:
- name: appearances

- kind: Character
ancestor: yes
properties:
- name: alive

- kind: Character
ancestor: yes
properties:
- name: family
- name: appearances

- kind: Character
ancestor: yes
properties:
- name: name
- name: family
54 changes: 33 additions & 21 deletions regression/datastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,22 @@ describe('datastore', function() {

describe('querying the datastore', function() {

var ancestor = ds.key(['Book', 'GoT']);

var keys = [
ds.key(['Character', 'Rickard']),
ds.key(['Character', 'Rickard', 'Character', 'Eddard']),
ds.key(['Character', 'Catelyn']),
ds.key(['Character', 'Eddard', 'Character', 'Arya']),
ds.key(['Character', 'Eddard', 'Character', 'Sansa']),
ds.key(['Character', 'Eddard', 'Character', 'Robb']),
ds.key(['Character', 'Eddard', 'Character', 'Bran']),
ds.key(['Character', 'Eddard', 'Character', 'Jon Snow'])
ds.key(['Book', 'GoT', 'Character', 'Rickard']),
ds.key(['Book', 'GoT', 'Character', 'Rickard', 'Character', 'Eddard']),
ds.key(['Book', 'GoT', 'Character', 'Catelyn']),
ds.key(['Book', 'GoT', 'Character', 'Rickard', 'Character', 'Eddard',
'Character', 'Arya']),
ds.key(['Book', 'GoT', 'Character', 'Rickard', 'Character', 'Eddard',
'Character', 'Sansa']),
ds.key(['Book', 'GoT', 'Character', 'Rickard', 'Character', 'Eddard',
'Character', 'Robb']),
ds.key(['Book', 'GoT', 'Character', 'Rickard', 'Character', 'Eddard',
'Character', 'Bran']),
ds.key(['Book', 'GoT', 'Character', 'Rickard', 'Character', 'Eddard',
'Character', 'Jon Snow'])
];

var characters = [{
Expand Down Expand Up @@ -223,7 +230,8 @@ describe('datastore', function() {
});

it('should limit queries', function(done) {
var q = ds.createQuery('Character').limit(5);
var q = ds.createQuery('Character').hasAncestor(ancestor)
.limit(5);
ds.runQuery(q, function(err, firstEntities, secondQuery) {
assert.ifError(err);
assert.equal(firstEntities.length, 5);
Expand All @@ -244,7 +252,8 @@ describe('datastore', function() {
});

it('should filter queries with simple indexes', function(done) {
var q = ds.createQuery('Character').filter('appearances >=', 20);
var q = ds.createQuery('Character').hasAncestor(ancestor)
.filter('appearances >=', 20);
ds.runQuery(q, function(err, entities) {
assert.ifError(err);
assert.equal(entities.length, 6);
Expand All @@ -253,7 +262,7 @@ describe('datastore', function() {
});

it('should filter queries with defined indexes', function(done) {
var q = ds.createQuery('Character')
var q = ds.createQuery('Character').hasAncestor(ancestor)
.filter('family =', 'Stark')
.filter('appearances >=', 20);
ds.runQuery(q, function(err, entities) {
Expand All @@ -265,17 +274,17 @@ describe('datastore', function() {

it('should filter by ancestor', function(done) {
var q = ds.createQuery('Character')
.hasAncestor(ds.key(['Character', 'Eddard']));
.hasAncestor(ancestor);
ds.runQuery(q, function(err, entities) {
assert.ifError(err);
assert.equal(entities.length, 5);
assert.equal(entities.length, 8);
done();
});
});

it('should filter by key', function(done) {
var q = ds.createQuery('Character')
.filter('__key__ =', ds.key(['Character', 'Rickard']));
var q = ds.createQuery('Character').hasAncestor(ancestor)
.filter('__key__ =', ds.key(['Book', 'GoT', 'Character', 'Rickard']));
ds.runQuery(q, function(err, entities) {
assert.ifError(err);
assert.equal(entities.length, 1);
Expand All @@ -284,7 +293,8 @@ describe('datastore', function() {
});

it('should order queries', function(done) {
var q = ds.createQuery('Character').order('appearances');
var q = ds.createQuery('Character').hasAncestor(ancestor)
.order('appearances');
ds.runQuery(q, function(err, entities) {
assert.ifError(err);
assert.equal(entities[0].data.name, characters[0].name);
Expand All @@ -294,7 +304,8 @@ describe('datastore', function() {
});

it('should select projections', function(done) {
var q = ds.createQuery('Character').select(['name', 'family']);
var q = ds.createQuery('Character').hasAncestor(ancestor)
.select(['name', 'family']);
ds.runQuery(q, function(err, entities) {
assert.ifError(err);
assert.deepEqual(entities[0].data, {
Expand All @@ -310,7 +321,7 @@ describe('datastore', function() {
});

it('should paginate with offset and limit', function(done) {
var q = ds.createQuery('Character')
var q = ds.createQuery('Character').hasAncestor(ancestor)
.offset(2)
.limit(3)
.order('appearances');
Expand All @@ -329,15 +340,15 @@ describe('datastore', function() {
});

it('should resume from a start cursor', function(done) {
var q = ds.createQuery('Character')
var q = ds.createQuery('Character').hasAncestor(ancestor)
.offset(2)
.limit(2)
.order('appearances');
ds.runQuery(q, function(err, entities, nextQuery) {
assert.ifError(err);
var startCursor = nextQuery.startVal;
var cursorQuery =
ds.createQuery('Character')
ds.createQuery('Character').hasAncestor(ancestor)
.order('appearances')
.start(startCursor);
ds.runQuery(cursorQuery, function(err, secondEntities) {
Expand All @@ -351,7 +362,8 @@ describe('datastore', function() {
});

it('should group queries', function(done) {
var q = ds.createQuery('Character').groupBy('alive');
var q = ds.createQuery('Character').hasAncestor(ancestor)
.groupBy('alive');
ds.runQuery(q, function(err, entities) {
assert.ifError(err);
assert.equal(entities.length, 2);
Expand Down

0 comments on commit 51abc0d

Please sign in to comment.