Skip to content

Commit

Permalink
pull in system tests env vars & run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
callmehiphop committed Oct 19, 2017
1 parent 57922bc commit f57858e
Showing 1 changed file with 38 additions and 25 deletions.
63 changes: 38 additions & 25 deletions packages/bigquery/benchmark/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@
const async = require('async');
const fs = require('fs');
const BigQuery = require('../src/index.js');
const env = require('../../../system-test/env.js');

if (process.argv.length < 3) {
throw `need query file; usage: \
'${process.argv[0]} ${process.argv[1]} <queries.json>'`;
throw new Error(`need query file; ` +
`usage: '${process.argv[0]} ${process.argv[1]} <queries.json>'`);
}

var queryJson = fs.readFileSync(process.argv[2]);
var queries = JSON.parse(queryJson);
var client = new BigQuery();
var client = new BigQuery(env);

var doQuery = function(queryTxt, callback) {
var startMilli = new Date().getTime();
Expand All @@ -39,28 +41,39 @@ var doQuery = function(queryTxt, callback) {
useLegacySql: false
};

client.createQueryStream(query)
.on('error', function(err) {
callback(err);
})
.on('data', function(row) {
if (numRows === 0) {
numCols = Object.keys(row).length;
timeFirstByteMilli = new Date().getTime() - startMilli;
} else if (numCols !== Object.keys(row).length) {
this.end();
callback(`query "${queryTxt}": wrong number of columns, \
want ${numCols} got ${Object.keys(row).length}`);
}
numRows++;
})
.on('end', function() {
var timeTotalMilli = new Date().getTime() - startMilli;
console.log(`query ${queryTxt}: got ${numRows} rows, ${numCols} cols, \
first byte ${timeFirstByteMilli / 1000} sec, \
total ${timeTotalMilli / 1000} sec`);
callback(null);
});
client
.createQueryStream(query)
.on('error', callback)
.on('data', function(row) {
if (numRows === 0) {
numCols = Object.keys(row).length;
timeFirstByteMilli = new Date().getTime() - startMilli;
} else if (numCols !== Object.keys(row).length) {
this.end();

var receivedCols = Object.keys(row).length;
var error = new Error(
`query "${queryTxt}": ` +
`wrong number of columns, want ${numCols} got ${receivedCols}`
);

callback(error);
}
numRows++;
})
.on('end', function() {
var timeTotalMilli = new Date().getTime() - startMilli;

console.log(
`query ${queryTxt}:`,
`got ${numRows} rows,`,
`${numCols} cols,`,
`first byte ${timeFirstByteMilli / 1000} sec,`,
`total ${timeTotalMilli / 1000} sec`
);

callback(null);
});
};

async.eachSeries(queries, doQuery, err => {
Expand Down

0 comments on commit f57858e

Please sign in to comment.