Skip to content

Commit

Permalink
test: ensure "total duration" > "duration of resolvers"
Browse files Browse the repository at this point in the history
Add test for #2298
  • Loading branch information
cheapsteak committed Feb 12, 2019
1 parent a46560b commit 2b5a041
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions packages/apollo-server-integration-testsuite/src/ApolloServer.ts
Expand Up @@ -37,6 +37,7 @@ import {
ApolloServerBase,
} from 'apollo-server-core';
import { GraphQLExtension, GraphQLResponse } from 'graphql-extensions';
import { TracingFormat } from 'apollo-tracing';

export function createServerInfo<AS extends ApolloServerBase>(
server: AS,
Expand Down Expand Up @@ -1260,5 +1261,46 @@ export function testApolloServer<AS extends ApolloServerBase>(
}, done.fail);
});
});

describe('Tracing', () => {
const typeDefs = gql`
type Book {
title: String
author: String
}
type Query {
books: [Book]
}
`;

const books = [{ title: 'H', author: 'J' }];

it('reports a total duration that is longer than the durations of its constituent resolvers', async () => {
const resolvers = {
Query: {
books: () =>
new Promise(resolve => setTimeout(() => resolve(books), 10)),
},
};

const { url: uri } = await createApolloServer({
typeDefs,
resolvers,
tracing: true,
});

const apolloFetch = createApolloFetch({ uri });
const result = await apolloFetch({
query: `{ books { title author } }`,
});

const tracing: TracingFormat = result.extensions.tracing;

tracing.execution.resolvers.forEach(resolver =>
expect(resolver.duration).toBeLessThan(tracing.duration),
);
});
});
});
}

0 comments on commit 2b5a041

Please sign in to comment.