Skip to content

Commit

Permalink
Add test cases for benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffRMoore committed Apr 14, 2016
1 parent 7a8f748 commit c9eadcc
Show file tree
Hide file tree
Showing 5 changed files with 269 additions and 134 deletions.
34 changes: 34 additions & 0 deletions benchmark/__tests__/calibration-test.js
@@ -0,0 +1,34 @@
/**
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

import { expect } from 'chai';
import { describe, it } from 'mocha';

import { benchmarks } from '../suite';

import { runBenchmarkTest, startBenchmarkTest } from 'async-benchmark-runner';

// 80+ char lines are useful in describe/it, so ignore in this file.
/* eslint-disable max-len */

describe('Benchmark Calibration Tests', () => {
describe('NO-OP Synchronous', () => {
it('returns false', () => {
const result = runBenchmarkTest(benchmarks, 'NO-OP Synchronous');
expect(result).to.equal(false);
});
});

describe('NO-OP Asynchronous', () => {
it('returns false', async () => {
const result = await startBenchmarkTest(benchmarks, 'NO-OP Asynchronous');
expect(result).to.equal(false);
});
});
});
103 changes: 103 additions & 0 deletions benchmark/__tests__/simplestObject-test.js
@@ -0,0 +1,103 @@
/**
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

import { expect } from 'chai';
import { describe, it } from 'mocha';

import { simplestObject, simplestObjectQuerySource } from '../simplestObject';

import { runBenchmarkTest, startBenchmarkTest } from 'async-benchmark-runner';

// 80+ char lines are useful in describe/it, so ignore in this file.
/* eslint-disable max-len */

describe('Benchmark Simplest object query Tests', () => {
describe('Simplest object query: parse', () => {
it('returns AST', () => {
const ast = runBenchmarkTest(simplestObject, 'Simplest object query: parse');
expect(ast).to.deep.equal({
kind: 'Document',
definitions:
[ { kind: 'OperationDefinition',
operation: 'query',
name: null,
selectionSet: {
kind: 'SelectionSet',
loc: {
end: 14,
source: {
body: simplestObjectQuerySource,
name: 'GraphQL'
},
start: 3
},
selections: [
{
alias: null,
arguments: [],
directives: [],
kind: 'Field',
loc: {
end: 10,
source: {
body: simplestObjectQuerySource,
name: 'GraphQL'
},
start: 9
},
name: {
kind: 'Name',
loc: {
end: 10,
source: {
body: simplestObjectQuerySource,
name: 'GraphQL'
},
start: 9
},
value: 'A'
},
selectionSet: null
}
]
},
variableDefinitions: null,
directives: [],
loc: {
end: 14,
source: {
body: simplestObjectQuerySource,
name: 'GraphQL'
},
start: 3
} } ],
loc: {
start: 3,
end: 17,
source: {
body: simplestObjectQuerySource,
name: 'GraphQL'
} } });
});
});

describe('Simplest object query: validate', () => {
it('returns no errors', () => {
const errors = runBenchmarkTest(simplestObject, 'Simplest object query: validate');
expect(errors).to.deep.equal([], 'Should validate');
});
});

describe('Simplest object query: execute', () => {
it('returns expected value', async () => {
const result = await startBenchmarkTest(simplestObject, 'Simplest object query: execute');
expect(result).to.deep.equal({data: {A: 'A'}});
});
});
});
193 changes: 96 additions & 97 deletions benchmark/simplestList.js
@@ -1,5 +1,4 @@
import {
graphql,
Source,
parse,
validate,
Expand All @@ -26,15 +25,15 @@ const schema = new GraphQLSchema({
args: {
id: { type: GraphQLString }
},
resolve: (source, args, context, info) => {
resolve: () => {
return data;
}
}
}
})
});

const simplestListQuery =
const simplestListQuery =
`
{
A
Expand All @@ -45,117 +44,117 @@ const rootValue = {
};

const record = {
A: 'A',
A: 'A',
};

let data;
let documentAST;

export const simplestList = [
{
name: 'Simplest list query: parse',
run: () => {
return parse(new Source(simplestListQuery));
}
},
{
name: 'Simplest list query: validate',
setUp: () => {
documentAST = parse(new Source(simplestListQuery));
{
name: 'Simplest list query: parse',
run: () => {
return parse(new Source(simplestListQuery));
}
},
tearDown: () => {
documentAST = null;
{
name: 'Simplest list query: validate',
setUp: () => {
documentAST = parse(new Source(simplestListQuery));
},
tearDown: () => {
documentAST = null;
},
run: () => {
return validate(schema, documentAST);
}
},
run: () => {
return validate(schema, documentAST);
}
},
{
name: 'Simplest list query: execute, n=1',
setUp: () => {
documentAST = parse(new Source(simplestListQuery));
data = [];
{
name: 'Simplest list query: execute, n=1',
setUp: () => {
documentAST = parse(new Source(simplestListQuery));
data = [];

for(let i=0; i < 1; i++) {
data.push(record);
for (let i = 0; i < 1; i++) {
data.push(record);
}
},
tearDown: () => {
documentAST = null;
data = [];
},
startRunning: () => {
return execute(
schema,
documentAST,
rootValue
);
}
},
tearDown: () => {
documentAST = null;
data = [];
},
startRunning: () => {
return execute(
schema,
documentAST,
rootValue
);
}
},
{
name: 'Simplest list query: execute, n=10',
setUp: () => {
documentAST = parse(new Source(simplestListQuery));
data = [];
{
name: 'Simplest list query: execute, n=10',
setUp: () => {
documentAST = parse(new Source(simplestListQuery));
data = [];

for(let i=0; i < 10; i++) {
data.push(record);
for (let i = 0; i < 10; i++) {
data.push(record);
}
},
tearDown: () => {
documentAST = null;
data = [];
},
startRunning: () => {
return execute(
schema,
documentAST,
rootValue
);
}
},
tearDown: () => {
documentAST = null;
data = [];
},
startRunning: () => {
return execute(
schema,
documentAST,
rootValue
);
}
},
{
name: 'Simplest list query: execute, n=100',
setUp: () => {
documentAST = parse(new Source(simplestListQuery));
data = [];
{
name: 'Simplest list query: execute, n=100',
setUp: () => {
documentAST = parse(new Source(simplestListQuery));
data = [];

for(let i=0; i < 100; i++) {
data.push(record);
for (let i = 0; i < 100; i++) {
data.push(record);
}
},
tearDown: () => {
documentAST = null;
data = [];
},
startRunning: () => {
return execute(
schema,
documentAST,
rootValue
);
}
},
tearDown: () => {
documentAST = null;
data = [];
},
startRunning: () => {
return execute(
schema,
documentAST,
rootValue
);
}
},
{
name: 'Simplest list query: execute, n=1000',
setUp: () => {
documentAST = parse(new Source(simplestListQuery));
data = [];
{
name: 'Simplest list query: execute, n=1000',
setUp: () => {
documentAST = parse(new Source(simplestListQuery));
data = [];

for(let i=0; i < 1000; i++) {
data.push(record);
for (let i = 0; i < 1000; i++) {
data.push(record);
}
},
tearDown: () => {
documentAST = null;
data = [];
},
startRunning: () => {
return execute(
schema,
documentAST,
rootValue
);
}
},
tearDown: () => {
documentAST = null;
data = [];
},
startRunning: () => {
return execute(
schema,
documentAST,
rootValue
);
}
}
];

0 comments on commit c9eadcc

Please sign in to comment.