Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix (regression tests): make datastore queries strongly consistent #267

Merged
merged 1 commit into from
Oct 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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