diff --git a/currencies.json b/currencies.json index d95e0986e5..9c4f7fa000 100644 --- a/currencies.json +++ b/currencies.json @@ -1324,4 +1324,4 @@ } ] } -] \ No newline at end of file +] diff --git a/packages/collector/test/integration/currencies/protocols/graphql/modes.json b/packages/collector/test/integration/currencies/protocols/graphql/modes.json new file mode 100644 index 0000000000..e33d7cc526 --- /dev/null +++ b/packages/collector/test/integration/currencies/protocols/graphql/modes.json @@ -0,0 +1 @@ +["raw", "apollo"] diff --git a/packages/collector/test/integration/currencies/protocols/graphql/test_base.js b/packages/collector/test/integration/currencies/protocols/graphql/test_base.js index 9477c7b0af..a3da771024 100644 --- a/packages/collector/test/integration/currencies/protocols/graphql/test_base.js +++ b/packages/collector/test/integration/currencies/protocols/graphql/test_base.js @@ -21,7 +21,7 @@ const globalAgent = require('@_local/collector/test/globalAgent'); const agentControls = globalAgent.instance; -module.exports = function (name, version, isLatest) { +module.exports = function (name, version, isLatest, mode) { this.timeout(config.getTestTimeout() * 5); if (!supportedVersion(process.versions.node)) { @@ -33,286 +33,284 @@ module.exports = function (name, version, isLatest) { const useAlias = Math.random >= 0.5; - ['raw', 'apollo'].forEach(type => { - describe(`${type} queries`, function () { - ['amqp', 'http'].forEach(communicationProtocol => { - if (type === 'apollo' && communicationProtocol === 'amqp') { - return it.skip('Test scenario Apollo & AMPQ is not supported.'); - } - - [false, true].forEach(withError => { - [false, true].forEach(queryShorthand => { - // eslint-disable-next-line max-len - const title = `withError: ${withError} queryShorthand: ${queryShorthand} useAlias: ${useAlias} communicationProtocol: ${communicationProtocol}`; - - describe(title, function () { - let serverControls; - let clientControls; - - before(async () => { - serverControls = new ProcessControls({ - dirname: __dirname, - appName: type === 'raw' ? 'rawGraphQLServer.js' : 'apolloServer.js', - useGlobalAgent: true, - env: { - LIBRARY_VERSION: version, - LIBRARY_NAME: name, - LIBRARY_LATEST: isLatest - } - }); - clientControls = new ProcessControls({ - dirname: __dirname, - appName: 'client', - useGlobalAgent: true, - env: { - LIBRARY_VERSION: version, - LIBRARY_NAME: name, - LIBRARY_LATEST: isLatest, - SERVER_PORT: serverControls.getPort() - } - }); - - await serverControls.startAndWaitForAgentConnection(); - await clientControls.startAndWaitForAgentConnection(); + describe(`${mode} queries`, function () { + ['amqp', 'http'].forEach(communicationProtocol => { + if (mode === 'apollo' && communicationProtocol === 'amqp') { + return it.skip('Test scenario Apollo & AMPQ is not supported.'); + } + + [false, true].forEach(withError => { + [false, true].forEach(queryShorthand => { + // eslint-disable-next-line max-len + const title = `withError: ${withError} queryShorthand: ${queryShorthand} useAlias: ${useAlias} communicationProtocol: ${communicationProtocol}`; + + describe(title, function () { + let serverControls; + let clientControls; + + before(async () => { + serverControls = new ProcessControls({ + dirname: __dirname, + appName: mode === 'raw' ? 'rawGraphQLServer.js' : 'apolloServer.js', + useGlobalAgent: true, + env: { + LIBRARY_VERSION: version, + LIBRARY_NAME: name, + LIBRARY_LATEST: isLatest + } }); - - beforeEach(async () => { - await agentControls.clearReceivedTraceData(); + clientControls = new ProcessControls({ + dirname: __dirname, + appName: 'client', + useGlobalAgent: true, + env: { + LIBRARY_VERSION: version, + LIBRARY_NAME: name, + LIBRARY_LATEST: isLatest, + SERVER_PORT: serverControls.getPort() + } }); - after(async () => { - await serverControls.stop(); - await clientControls.stop(); - }); + await serverControls.startAndWaitForAgentConnection(); + await clientControls.startAndWaitForAgentConnection(); + }); - it.skip('must trace a query with a value resolver', () => { - const resolverType = 'value'; - const multipleEntities = null; - - const queryParams = [ - withError ? 'withError=yes' : null, - queryShorthand ? 'queryShorthand=yes' : null, - multipleEntities ? 'multipleEntities=yes' : null, - useAlias ? 'useAlias=yes' : null, - `communicationProtocol=${communicationProtocol}` - ] - .filter(param => !!param) - .join('&'); - - const url = queryParams ? `/${resolverType}?${queryParams}` : `/${resolverType}`; - - return clientControls - .sendRequest({ - method: 'POST', - path: url - }) - .then(response => { - const entityName = withError ? `${resolverType}Error` : resolverType; - const entityNameWithAlias = useAlias ? `${entityName}Alias` : entityName; - - checkQueryResponse(entityNameWithAlias, withError, null, response); - - return retry(() => { - return agentControls.getSpans().then(spans => { - return verifySpansForQuery( - { - resolverType, - entityName, - withError, - queryShorthand, - multipleEntities, - communicationProtocol - }, - spans - ); - }); - }); - }); - }); + beforeEach(async () => { + await agentControls.clearReceivedTraceData(); + }); - it('must trace a query with a promise resolver', () => { - const resolverType = 'promise'; - const multipleEntities = null; - - const queryParams = [ - withError ? 'withError=yes' : null, - queryShorthand ? 'queryShorthand=yes' : null, - multipleEntities ? 'multipleEntities=yes' : null, - useAlias ? 'useAlias=yes' : null, - `communicationProtocol=${communicationProtocol}` - ] - .filter(param => !!param) - .join('&'); - - const url = queryParams ? `/${resolverType}?${queryParams}` : `/${resolverType}`; - - return clientControls - .sendRequest({ - method: 'POST', - path: url - }) - .then(response => { - const entityName = withError ? `${resolverType}Error` : resolverType; - const entityNameWithAlias = useAlias ? `${entityName}Alias` : entityName; - - checkQueryResponse(entityNameWithAlias, withError, null, response); - - return retry(() => - agentControls.getSpans().then( - verifySpansForQuery.bind(null, { - resolverType, - entityName, - withError, - queryShorthand, - multipleEntities, - communicationProtocol - }) - ) - ); - }); - }); + after(async () => { + await serverControls.stop(); + await clientControls.stop(); + }); - it('must trace a query which resolves to an array of promises', () => { - const resolverType = 'array'; - const multipleEntities = null; - - const queryParams = [ - withError ? 'withError=yes' : null, - queryShorthand ? 'queryShorthand=yes' : null, - multipleEntities ? 'multipleEntities=yes' : null, - useAlias ? 'useAlias=yes' : null, - `communicationProtocol=${communicationProtocol}` - ] - .filter(param => !!param) - .join('&'); - - const url = queryParams ? `/${resolverType}?${queryParams}` : `/${resolverType}`; - - return clientControls - .sendRequest({ - method: 'POST', - path: url - }) - .then(response => { - const entityName = withError ? `${resolverType}Error` : resolverType; - const entityNameWithAlias = useAlias ? `${entityName}Alias` : entityName; - - checkQueryResponse(entityNameWithAlias, withError, null, response); - - return retry(() => - agentControls.getSpans().then( - verifySpansForQuery.bind(null, { + it.skip('must trace a query with a value resolver', () => { + const resolverType = 'value'; + const multipleEntities = null; + + const queryParams = [ + withError ? 'withError=yes' : null, + queryShorthand ? 'queryShorthand=yes' : null, + multipleEntities ? 'multipleEntities=yes' : null, + useAlias ? 'useAlias=yes' : null, + `communicationProtocol=${communicationProtocol}` + ] + .filter(param => !!param) + .join('&'); + + const url = queryParams ? `/${resolverType}?${queryParams}` : `/${resolverType}`; + + return clientControls + .sendRequest({ + method: 'POST', + path: url + }) + .then(response => { + const entityName = withError ? `${resolverType}Error` : resolverType; + const entityNameWithAlias = useAlias ? `${entityName}Alias` : entityName; + + checkQueryResponse(entityNameWithAlias, withError, null, response); + + return retry(() => { + return agentControls.getSpans().then(spans => { + return verifySpansForQuery( + { resolverType, entityName, withError, queryShorthand, multipleEntities, communicationProtocol - }) - ) - ); + }, + spans + ); + }); }); - }); + }); + }); - it('must trace a query with multiple entities', () => { - const resolverType = 'array'; - const multipleEntities = true; - - const queryParams = [ - withError ? 'withError=yes' : null, - queryShorthand ? 'queryShorthand=yes' : null, - multipleEntities ? 'multipleEntities=yes' : null, - useAlias ? 'useAlias=yes' : null, - `communicationProtocol=${communicationProtocol}` - ] - .filter(param => !!param) - .join('&'); - - const url = queryParams ? `/${resolverType}?${queryParams}` : `/${resolverType}`; - - return clientControls - .sendRequest({ - method: 'POST', - path: url - }) - .then(response => { - const entityName = withError ? `${resolverType}Error` : resolverType; - const entityNameWithAlias = useAlias ? `${entityName}Alias` : entityName; - - checkQueryResponse(entityNameWithAlias, withError, null, response); - - return retry(() => - agentControls.getSpans().then( - verifySpansForQuery.bind(null, { - resolverType, - entityName, - withError, - queryShorthand, - multipleEntities, - communicationProtocol - }) - ) - ); - }); - }); + it('must trace a query with a promise resolver', () => { + const resolverType = 'promise'; + const multipleEntities = null; + + const queryParams = [ + withError ? 'withError=yes' : null, + queryShorthand ? 'queryShorthand=yes' : null, + multipleEntities ? 'multipleEntities=yes' : null, + useAlias ? 'useAlias=yes' : null, + `communicationProtocol=${communicationProtocol}` + ] + .filter(param => !!param) + .join('&'); + + const url = queryParams ? `/${resolverType}?${queryParams}` : `/${resolverType}`; + + return clientControls + .sendRequest({ + method: 'POST', + path: url + }) + .then(response => { + const entityName = withError ? `${resolverType}Error` : resolverType; + const entityNameWithAlias = useAlias ? `${entityName}Alias` : entityName; + + checkQueryResponse(entityNameWithAlias, withError, null, response); + + return retry(() => + agentControls.getSpans().then( + verifySpansForQuery.bind(null, { + resolverType, + entityName, + withError, + queryShorthand, + multipleEntities, + communicationProtocol + }) + ) + ); + }); + }); + + it('must trace a query which resolves to an array of promises', () => { + const resolverType = 'array'; + const multipleEntities = null; + + const queryParams = [ + withError ? 'withError=yes' : null, + queryShorthand ? 'queryShorthand=yes' : null, + multipleEntities ? 'multipleEntities=yes' : null, + useAlias ? 'useAlias=yes' : null, + `communicationProtocol=${communicationProtocol}` + ] + .filter(param => !!param) + .join('&'); + + const url = queryParams ? `/${resolverType}?${queryParams}` : `/${resolverType}`; + + return clientControls + .sendRequest({ + method: 'POST', + path: url + }) + .then(response => { + const entityName = withError ? `${resolverType}Error` : resolverType; + const entityNameWithAlias = useAlias ? `${entityName}Alias` : entityName; + + checkQueryResponse(entityNameWithAlias, withError, null, response); + + return retry(() => + agentControls.getSpans().then( + verifySpansForQuery.bind(null, { + resolverType, + entityName, + withError, + queryShorthand, + multipleEntities, + communicationProtocol + }) + ) + ); + }); + }); + + it('must trace a query with multiple entities', () => { + const resolverType = 'array'; + const multipleEntities = true; + + const queryParams = [ + withError ? 'withError=yes' : null, + queryShorthand ? 'queryShorthand=yes' : null, + multipleEntities ? 'multipleEntities=yes' : null, + useAlias ? 'useAlias=yes' : null, + `communicationProtocol=${communicationProtocol}` + ] + .filter(param => !!param) + .join('&'); + + const url = queryParams ? `/${resolverType}?${queryParams}` : `/${resolverType}`; + + return clientControls + .sendRequest({ + method: 'POST', + path: url + }) + .then(response => { + const entityName = withError ? `${resolverType}Error` : resolverType; + const entityNameWithAlias = useAlias ? `${entityName}Alias` : entityName; + + checkQueryResponse(entityNameWithAlias, withError, null, response); + + return retry(() => + agentControls.getSpans().then( + verifySpansForQuery.bind(null, { + resolverType, + entityName, + withError, + queryShorthand, + multipleEntities, + communicationProtocol + }) + ) + ); + }); }); }); }); }); + }); - describe(`${type}: mutations`, function () { - let serverControls; - let clientControls; - - before(async () => { - serverControls = new ProcessControls({ - dirname: __dirname, - appName: type === 'raw' ? 'rawGraphQLServer.js' : 'apolloServer.js', - useGlobalAgent: true, - env: { - LIBRARY_VERSION: version, - LIBRARY_NAME: name, - LIBRARY_LATEST: isLatest - } - }); - clientControls = new ProcessControls({ - dirname: __dirname, - appName: 'client', - useGlobalAgent: true, - env: { - LIBRARY_VERSION: version, - LIBRARY_NAME: name, - LIBRARY_LATEST: isLatest, - SERVER_PORT: serverControls.getPort() - } - }); - - await serverControls.startAndWaitForAgentConnection(); - await clientControls.startAndWaitForAgentConnection(); + describe(`${mode}: mutations`, function () { + let serverControls; + let clientControls; + + before(async () => { + serverControls = new ProcessControls({ + dirname: __dirname, + appName: mode === 'raw' ? 'rawGraphQLServer.js' : 'apolloServer.js', + useGlobalAgent: true, + env: { + LIBRARY_VERSION: version, + LIBRARY_NAME: name, + LIBRARY_LATEST: isLatest + } }); - - beforeEach(async () => { - await agentControls.clearReceivedTraceData(); + clientControls = new ProcessControls({ + dirname: __dirname, + appName: 'client', + useGlobalAgent: true, + env: { + LIBRARY_VERSION: version, + LIBRARY_NAME: name, + LIBRARY_LATEST: isLatest, + SERVER_PORT: serverControls.getPort() + } }); - after(async () => { - await serverControls.stop(); - await clientControls.stop(); - }); + await serverControls.startAndWaitForAgentConnection(); + await clientControls.startAndWaitForAgentConnection(); + }); - it('must trace a mutation', () => { - const url = '/mutation'; - - return clientControls - .sendRequest({ - method: 'POST', - path: url - }) - .then(response => { - checkMutationResponse(response); - return retry(() => agentControls.getSpans().then(verifySpansForMutation)); - }); - }); + beforeEach(async () => { + await agentControls.clearReceivedTraceData(); + }); + + after(async () => { + await serverControls.stop(); + await clientControls.stop(); + }); + + it('must trace a mutation', () => { + const url = '/mutation'; + + return clientControls + .sendRequest({ + method: 'POST', + path: url + }) + .then(response => { + checkMutationResponse(response); + return retry(() => agentControls.getSpans().then(verifySpansForMutation)); + }); }); }); });