From 604e28533ce36dbf7c3e5ddd299cbec5a717b82e Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Wed, 19 Oct 2016 16:58:57 +0200 Subject: [PATCH] Fix and improve test --- .../leader-multiple-users-query-order.test.js | 65 ++++++++++++------- 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/test/acceptance/batch/leader-multiple-users-query-order.test.js b/test/acceptance/batch/leader-multiple-users-query-order.test.js index 3b076545..782dee19 100644 --- a/test/acceptance/batch/leader-multiple-users-query-order.test.js +++ b/test/acceptance/batch/leader-multiple-users-query-order.test.js @@ -11,9 +11,14 @@ describe('multiple batch clients and users, job query order', function() { this.batchTestClientA = new BatchTestClient({ name: 'consumerA' }); this.batchTestClientB = new BatchTestClient({ name: 'consumerB' }); - this.testClientA = new TestClient(); - this.testClientA.getResult( - 'drop table if exists ordered_inserts; create table ordered_inserts (status numeric)', + this.testClient = new TestClient(); + this.testClient.getResult( + [ + 'drop table if exists ordered_inserts_a', + 'drop table if exists ordered_inserts_bbbbb', + 'create table ordered_inserts_a (status numeric)', + 'create table ordered_inserts_bbbbb (status numeric)' + ].join(';'), done ); }); @@ -36,16 +41,16 @@ describe('multiple batch clients and users, job query order', function() { it('should run job queries in order (multiple consumers)', function (done) { var jobRequestA1 = createJob([ - "insert into ordered_inserts values(1)", + "insert into ordered_inserts_a values(1)", "select pg_sleep(0.25)", - "insert into ordered_inserts values(2)" + "insert into ordered_inserts_a values(2)" ]); var jobRequestA2 = createJob([ - "insert into ordered_inserts values(3)" + "insert into ordered_inserts_a values(3)" ]); var jobRequestB1 = createJob([ - "insert into ordered_inserts values(4)" + "insert into ordered_inserts_bbbbb values(1)" ]); var self = this; @@ -55,14 +60,14 @@ describe('multiple batch clients and users, job query order', function() { return done(err); } - // we don't care about the producer - self.batchTestClientB.createJob(jobRequestA2, function(err, jobResultA2) { + var override = { host: 'cartodb250user.cartodb.com' }; + self.batchTestClientB.createJob(jobRequestB1, override, function(err, jobResultB1) { if (err) { return done(err); } - var override = { host: 'cartodb250user.cartodb.com' }; - self.batchTestClientB.createJob(jobRequestB1, override, function(err, jobResultB1) { + // we don't care about the producer + self.batchTestClientB.createJob(jobRequestA2, function(err, jobResultA2) { if (err) { return done(err); } @@ -80,23 +85,35 @@ describe('multiple batch clients and users, job query order', function() { assert.equal(jobA2.status, JobStatus.DONE); assert.equal(jobB1.status, JobStatus.DONE); - self.testClientA.getResult('select * from ordered_inserts', function(err, rows) { + assert.ok( + new Date(jobA1.updated_at).getTime() < new Date(jobA2.updated_at).getTime(), + 'A1 (' + jobA1.updated_at + ') ' + + 'should finish before A2 (' + jobA2.updated_at + ')' + ); + assert.ok( + new Date(jobB1.updated_at).getTime() < new Date(jobA1.updated_at).getTime(), + 'B1 (' + jobA1.updated_at + ') ' + + 'should finish before A1 (' + jobA1.updated_at + ')' + ); + + function statusMapper (status) { return { status: status }; } + + self.testClient.getResult('select * from ordered_inserts_a', function(err, rows) { assert.ok(!err); // cartodb250user and vizzuality test users share database - var expectedRows = [1, 4, 2, 3].map(function(status) { return {status: status}; }); + var expectedRows = [1, 2, 3].map(statusMapper); assert.deepEqual(rows, expectedRows); - assert.ok( - new Date(jobA1.updated_at).getTime() < new Date(jobA2.updated_at).getTime(), - 'A1 (' + jobA1.updated_at + ') ' + - 'should finish before A2 (' + jobA2.updated_at + ')' - ); - assert.ok( - new Date(jobB1.updated_at).getTime() < new Date(jobA1.updated_at).getTime(), - 'B1 (' + jobA1.updated_at + ') ' + - 'should finish before A1 (' + jobA1.updated_at + ')' - ); - done(); + + var query = 'select * from ordered_inserts_bbbbb'; + self.testClient.getResult(query, override, function(err, rows) { + assert.ok(!err); + + var expectedRows = [1].map(statusMapper); + assert.deepEqual(rows, expectedRows); + + done(); + }); }); });