From 4b76ae86d141f57e65b1a99a09f86278d56a368a Mon Sep 17 00:00:00 2001 From: Yongseok Kang <616895+feelform@users.noreply.github.com> Date: Tue, 23 Nov 2021 23:20:08 +0900 Subject: [PATCH] [#98] Fix no details error case informations to Error callstack By using the string return value of the stack in the toString method of Error, the developer can check the error information in detail. Fix redis 4.0 redis connection error - upgrade testcontainer to v7 --- .github/workflows/main.yml | 1 - .nycrc | 2 +- lib/context/span-event-recorder.js | 3 +- package.json | 6 +- test/agent.test.js | 2 +- .../fix-async-call-stack.test.js | 2 +- test/instrumentation/module/express.test.js | 280 ++++++++++++------ test/instrumentation/module/fix-redis.test.js | 6 +- test/instrumentation/module/http.test.js | 4 +- .../module/mongodb-core.test.js | 20 +- 10 files changed, 215 insertions(+), 111 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b9f82eaa..8657d6fd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,7 +20,6 @@ jobs: name: Node ${{ matrix.node_version }} on ubuntu-latest steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v2 - name: setup node environment uses: actions/setup-node@v2 diff --git a/.nycrc b/.nycrc index 237faf59..f4f2f13d 100644 --- a/.nycrc +++ b/.nycrc @@ -1,3 +1,3 @@ { - "exclude": ["lib/data/grpc/**/*", "test/**/*"] + "exclude": ["lib/data/v1/**/*", "test/**/*"] } \ No newline at end of file diff --git a/lib/context/span-event-recorder.js b/lib/context/span-event-recorder.js index 67807caf..a2cbdd16 100644 --- a/lib/context/span-event-recorder.js +++ b/lib/context/span-event-recorder.js @@ -126,9 +126,10 @@ class SpanEventRecorder { recordException(error, isError) { if (this.spanEvent && error) { const metaInfo = StringMetaService.get(error.name || 'Error') + const errorMessage = error && typeof error.stack === 'string' ? error.stack.split(/\r?\n/, 2).join('') : '' this.spanEvent.exceptionInfo = { intValue: metaInfo.stringId, - stringValue: error.toString(), + stringValue: errorMessage, } if (this.span && isError) { this.span.err = 1 diff --git a/package.json b/package.json index 3f8d5bf1..33a20888 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pinpoint-node-agent", - "version": "0.9.0-next.1", + "version": "0.9.0-next.2", "main": "index.js", "scripts": { "test": "./node_modules/.bin/tape ./test/**/*.test.js", @@ -86,13 +86,13 @@ "mongoose": "^5.4.3", "npm-run-all": "^1.7.0", "nyc": "^15.1.0", - "redis": ">=3.1.1", + "redis": "^3.1.2", "redis-mock": "^0.49.0", "request": "^2.88.0", "rewire": "^4.0.1", "rimraf": "^2.6.2", "tap-spec": "^5.0.0", "tape": "^4.9.1", - "testcontainers": "^2.8.0" + "testcontainers": "^7.24.0" } } diff --git a/test/agent.test.js b/test/agent.test.js index 651d2e9c..7b1040b0 100644 --- a/test/agent.test.js +++ b/test/agent.test.js @@ -14,5 +14,5 @@ test('Should initialize agent', function (t) { const agent = require('./support/agent-singleton-mock') t.ok(agent) - t.equal(agent.pinpointClient.agentInfo.agentVersion, '0.9.0-next.1', 'agent version from package.json') + t.equal(agent.pinpointClient.agentInfo.agentVersion, '0.9.0-next.2', 'agent version from package.json') }) diff --git a/test/instrumentation/fix-async-call-stack.test.js b/test/instrumentation/fix-async-call-stack.test.js index 3d2eaeea..2d4d6e49 100644 --- a/test/instrumentation/fix-async-call-stack.test.js +++ b/test/instrumentation/fix-async-call-stack.test.js @@ -21,7 +21,7 @@ test(`fix redis call stack depth`, async (t) => { const redis = require('redis') const client = redis.createClient( container.getMappedPort(6379), - container.getContainerIpAddress(), + container.getHost(), ) client.set("key", "value", async function (error) { diff --git a/test/instrumentation/module/express.test.js b/test/instrumentation/module/express.test.js index 384f4baa..b231d452 100644 --- a/test/instrumentation/module/express.test.js +++ b/test/instrumentation/module/express.test.js @@ -7,7 +7,7 @@ const test = require('tape') const axios = require('axios') -const { log } = require('../../test-helper') +const { log, util } = require('../../test-helper') const agent = require('../../support/agent-singleton-mock') const express = require('express') const DefaultAnnotationKey = require('../../../lib/constant/annotation-key').DefaultAnnotationKey @@ -38,7 +38,7 @@ test(`${testName1} Should record request in basic route`, function (t) { t.equal(trace.span.annotations[0].key, DefaultAnnotationKey.HTTP_PARAM.name, 'HTTP param key match') t.equal(trace.span.annotations[0].value.stringValue, 'api=test&test1=test', 'HTTP param value match') - const actualBuilder = new MethodDescriptorBuilder('express', 'app.get') + let actualBuilder = new MethodDescriptorBuilder('express', 'app.get') .setParameterDescriptor('(path, callback)') .setLineNumber(481) .setFileName('application.js') @@ -56,21 +56,16 @@ test(`${testName1} Should record request in basic route`, function (t) { t.equal(actualMethodDescriptor.objectPath, 'app.get', 'objectPath') t.true(actualMethodDescriptor.location.length > 0, 'location') - const actualAppGetApiMetaInfo = apiMetaService.dataSender.mockAPIMetaInfos[0] - spanEvent = trace.storage.storage[1] - t.equal(actualAppGetApiMetaInfo.apiId, spanEvent.apiId, 'apiId') - t.equal(actualAppGetApiMetaInfo.apiInfo, 'express.Function.app.get(path, callback)', 'apiInfo') - t.equal(actualAppGetApiMetaInfo.type, 0, 'type') - t.equal(actualAppGetApiMetaInfo.lineNumber, 481, 'line number') - t.true(actualAppGetApiMetaInfo.location.endsWith('application.js'), 'location') - - const actualHandleApiMetaInfo = apiMetaService.dataSender.mockAPIMetaInfos[1] + actualBuilder = new MethodDescriptorBuilder(undefined, '') + .setLineNumber(33) + .setFileName('express.test.js') + const actualHandlerMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder) spanEvent = trace.storage.storage[0] - t.equal(actualHandleApiMetaInfo.apiId, spanEvent.apiId, 'apiId') - t.equal(actualHandleApiMetaInfo.apiInfo, 'Test.()', 'apiInfo') - t.equal(actualHandleApiMetaInfo.type, 0, 'type') - t.equal(actualHandleApiMetaInfo.lineNumber, 33, 'line number') - t.true(actualHandleApiMetaInfo.location.endsWith('express.test.js'), 'location') + t.equal(actualHandlerMethodDescriptor.apiId, spanEvent.apiId, 'apiId') + t.equal(actualHandlerMethodDescriptor.apiDescriptor, 'Test.()', 'apiInfo') + t.equal(actualHandlerMethodDescriptor.type, 0, 'type') + t.equal(actualHandlerMethodDescriptor.lineNumber, 33, 'line number') + t.true(actualHandlerMethodDescriptor.location.endsWith('express.test.js'), 'location') }) }) @@ -81,12 +76,12 @@ test(`${testName1} Should record request in basic route`, function (t) { const trace = agent.traceContext.currentTraceObject() t.false(trace.span.annotations[0], 'HTTP param undefined case') - const actualBuilder = new MethodDescriptorBuilder('express', 'app.post') + let actualBuilder = new MethodDescriptorBuilder('express', 'app.post') .setParameterDescriptor('(path, callback)') .setLineNumber(481) .setFileName('application.js') const actualMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder) - const spanEvent = trace.storage.storage[1] + let spanEvent = trace.storage.storage[1] t.equal(actualMethodDescriptor.apiId, spanEvent.apiId, 'apiId') t.equal(spanEvent.annotations[0].key, -1, 'parameter') t.equal(spanEvent.annotations[0].value.stringValue, '/express1', 'parameter value matching') @@ -97,67 +92,95 @@ test(`${testName1} Should record request in basic route`, function (t) { t.equal(actualMethodDescriptor.methodName, 'post', 'methodName') t.equal(actualMethodDescriptor.moduleName, 'express', 'moduleName') t.equal(actualMethodDescriptor.objectPath, 'app.post', 'objectPath') + t.true(actualMethodDescriptor.location.endsWith('application.js'), 'location') + + actualBuilder = new MethodDescriptorBuilder(undefined, '') + .setLineNumber(72) + .setFileName('express.test.js') + const actualHandlerMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder) + spanEvent = trace.storage.storage[0] + t.equal(actualHandlerMethodDescriptor.apiId, spanEvent.apiId, 'apiId') + t.equal(actualHandlerMethodDescriptor.apiDescriptor, 'Test.()', 'apiInfo') + t.equal(actualHandlerMethodDescriptor.type, 0, 'type') + t.equal(actualHandlerMethodDescriptor.lineNumber, 72, 'line number') + t.true(actualHandlerMethodDescriptor.location.endsWith('express.test.js'), 'location') }) }) - /* - app.get('/express2', async (req, res) => { - process.nextTick(() => { - res.send('ok get') - - const trace = agent.traceContext.currentTraceObject() - const actualBuilder = new MethodDescriptorBuilder('express', 'app.get()') - .setFullName('express.app.get(path, callback)') - const actualMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder) - const spanEvent = trace.storage.storage[1] - t.equal(actualMethodDescriptor.apiId, spanEvent.apiId, 'apiId') - t.equal(spanEvent.annotations[0].key, -1, 'parameter') - t.equal(spanEvent.annotations[0].value.stringValue, '/express2', 'parameter value matching') - t.true(actualMethodDescriptor.apiDescriptor.startsWith('express.Function.app.get(path, callback)'), 'apiDescriptor') - t.equal(actualMethodDescriptor.className, 'Function', 'className') - t.equal(actualMethodDescriptor.fullName, 'express.app.get(path, callback)', 'fullName') - t.equal(actualMethodDescriptor.lineNumber, 481, 'lineNumber') - t.equal(actualMethodDescriptor.methodName, 'get', 'methodName') - t.equal(actualMethodDescriptor.moduleName, 'express', 'moduleName') - t.equal(actualMethodDescriptor.objectPath, 'app.get', 'objectPath') - - const actualGetAPIMetaInfo = apiMetaService.dataSender.mockAPIMetaInfos[0] - t.equal(actualGetAPIMetaInfo.apiInfo, 'express.Function.app.get(path, callback)', 'apiInfo') - t.equal(actualGetAPIMetaInfo.lineNumber, 481, 'apiInfo') - t.true(actualGetAPIMetaInfo.location.endsWith('node_modules/express/lib/application.js'), 'location') - const actualUserCodeAPIMetaInfo = apiMetaService.dataSender.mockAPIMetaInfos[1] - }) - }) - - let errorOrder = 0 - let pathSymbol - - const express3Symbol = Symbol('express3') - app.get('/express3', (req, res, next) => { - errorOrder++ - pathSymbol = express3Symbol - throw new Error('error case') + + app.get('/express2', async (req, res) => { + process.nextTick(() => { + res.send('ok get') + + const trace = agent.traceContext.currentTraceObject() + let actualBuilder = new MethodDescriptorBuilder('express', 'app.get') + .setParameterDescriptor('(path, callback)') + .setLineNumber(481) + .setFileName('application.js') + const actualMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder) + let spanEvent = trace.storage.storage[1] + t.equal(actualMethodDescriptor.apiId, spanEvent.apiId, 'apiId') + t.equal(spanEvent.annotations[0].key, -1, 'parameter') + t.equal(spanEvent.annotations[0].value.stringValue, '/express2', 'parameter value matching') + t.true(actualMethodDescriptor.apiDescriptor.startsWith('express.Function.app.get(path, callback)'), 'apiDescriptor') + t.equal(actualMethodDescriptor.className, 'Function', 'className') + t.equal(actualMethodDescriptor.fullName, 'express.app.get(path, callback)', 'fullName') + t.equal(actualMethodDescriptor.lineNumber, 481, 'lineNumber') + t.equal(actualMethodDescriptor.methodName, 'get', 'methodName') + t.equal(actualMethodDescriptor.moduleName, 'express', 'moduleName') + t.equal(actualMethodDescriptor.objectPath, 'app.get', 'objectPath') + t.true(actualMethodDescriptor.location.endsWith('application.js'), 'location') + + actualBuilder = new MethodDescriptorBuilder(undefined, '') + .setLineNumber(110) + .setFileName('express.test.js') + const actualHandlerMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder) + spanEvent = trace.storage.storage[0] + t.equal(actualHandlerMethodDescriptor.apiId, spanEvent.apiId, 'apiId') + t.equal(actualHandlerMethodDescriptor.apiDescriptor, 'Test.()', 'apiInfo') + t.equal(actualHandlerMethodDescriptor.type, 0, 'type') + t.equal(actualHandlerMethodDescriptor.lineNumber, 110, 'line number') + t.true(actualHandlerMethodDescriptor.location.endsWith('express.test.js'), 'location') }) - - const express4Symbol = Symbol('express4') - app.get('/express4', (req, res, next) => { - errorOrder++ - pathSymbol = express4Symbol - next(new Error('error case')) - - process.nextTick(() => { - const trace = agent.traceContext.currentTraceObject() - }) + }) + + let errorOrder = 0 + let pathSymbol + + const express3Symbol = Symbol('express3') + app.get('/express3', (req, res, next) => { + errorOrder++ + pathSymbol = express3Symbol + throw new Error('error case') + }) + + const express4Symbol = Symbol('express4') + app.get('/express4', (req, res, next) => { + errorOrder++ + pathSymbol = express4Symbol + next(new Error('error case')) + + process.nextTick(() => { + const trace = agent.traceContext.currentTraceObject() }) - - app.use(function (err, req, res, next) { - if (pathSymbol == express3Symbol) { - t.equal(errorOrder, 1, 'express3 error order') - } - if (pathSymbol === express4Symbol) { - t.equal(errorOrder, 2, 'express4 error order') + }) + + app.use(function (err, req, res, next) { + if (pathSymbol == express3Symbol) { + t.equal(errorOrder, 1, 'express3 error order') + } + if (pathSymbol === express4Symbol) { + t.equal(errorOrder, 2, 'express4 error order') + } + process.nextTick(() => { + const trace = agent.traceContext.currentTraceObject() + if (errorOrder == 1) { + noHandleTest(trace, t) + } else if (errorOrder == 2) { + errorHandleTest(trace, t) } res.status(500).send('Something broke!') - })*/ + }) + }) const server = app.listen(TEST_ENV.port, async function () { const result1 = await axios.get(getServerUrl(PATH) + '?api=test&test1=test') @@ -166,20 +189,20 @@ test(`${testName1} Should record request in basic route`, function (t) { const result2 = await axios.post(getServerUrl(PATH)) t.equal(result2.status, 200) - // const result3 = await axios.get(getServerUrl('/express2')) - // t.equal(result3.status, 200) + const result3 = await axios.get(getServerUrl('/express2')) + t.equal(result3.status, 200) - // try { - // await axios.get(getServerUrl('/express3')) - // } catch (error) { - // t.equal(error.response.status, 500) - // } + try { + await axios.get(getServerUrl('/express3')) + } catch (error) { + t.equal(error.response.status, 500) + } - // try { - // await axios.get(getServerUrl('/express4')) - // } catch (error) { - // t.equal(error.response.status, 500, 'axios.get(getServerUrl(/express4))') - // } + try { + await axios.get(getServerUrl('/express4')) + } catch (error) { + t.equal(error.response.status, 500, 'axios.get(getServerUrl(/express4))') + } const traceMap = agent.traceContext.getAllTraceObject() log.info(traceMap.size) @@ -190,7 +213,88 @@ test(`${testName1} Should record request in basic route`, function (t) { }) }) -/* +function noHandleTest(trace, t) { + let actualBuilder = new MethodDescriptorBuilder('express', 'app.get') + .setParameterDescriptor('(path, callback)') + .setLineNumber(481) + .setFileName('application.js') + const actualMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder) + let spanEvent = trace.storage.storage[2] + t.equal(actualMethodDescriptor.apiId, spanEvent.apiId, 'apiId') + t.equal(spanEvent.annotations[0].key, -1, 'parameter') + t.equal(spanEvent.annotations[0].value.stringValue, '/express3', 'parameter value matching') + t.true(actualMethodDescriptor.apiDescriptor.startsWith('express.Function.app.get(path, callback)'), 'apiDescriptor') + t.equal(actualMethodDescriptor.className, 'Function', 'className') + t.equal(actualMethodDescriptor.fullName, 'express.app.get(path, callback)', 'fullName') + t.equal(actualMethodDescriptor.lineNumber, 481, 'lineNumber') + t.equal(actualMethodDescriptor.methodName, 'get', 'methodName') + t.equal(actualMethodDescriptor.moduleName, 'express', 'moduleName') + t.equal(actualMethodDescriptor.objectPath, 'app.get', 'objectPath') + t.true(actualMethodDescriptor.location.endsWith('application.js'), 'location') + t.equal(spanEvent.sequence, 0, 'sequence') + t.equal(spanEvent.depth, 1, 'spanEvent.depth') + + actualBuilder = new MethodDescriptorBuilder(undefined, '') + .setLineNumber(150) + .setFileName('express.test.js') + const actualHandlerMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder) + spanEvent = trace.storage.storage[1] + t.equal(spanEvent.sequence, 1, 'sequence') + t.equal(spanEvent.depth, 2, 'spanEvent.depth') + t.equal(actualHandlerMethodDescriptor.apiId, spanEvent.apiId, 'apiId') + t.equal(actualHandlerMethodDescriptor.apiDescriptor, 'Test.()', 'apiInfo') + t.equal(actualHandlerMethodDescriptor.type, 0, 'type') + t.equal(actualHandlerMethodDescriptor.lineNumber, 150, 'line number') + t.true(actualHandlerMethodDescriptor.location.endsWith('express.test.js'), 'location') + + spanEvent = trace.storage.storage[0] + t.equal(spanEvent.sequence, 2, 'sequence') + t.equal(spanEvent.depth, 3, 'spanEvent.depth') + t.equal(spanEvent.exceptionInfo.intValue, 1, 'error value') + t.true(spanEvent.exceptionInfo.stringValue.endsWith('express.test.js:153:11'), 'error case') +} + +function errorHandleTest(trace, t) { + let actualBuilder = new MethodDescriptorBuilder('express', 'app.get') + .setParameterDescriptor('(path, callback)') + .setLineNumber(481) + .setFileName('application.js') + const actualMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder) + let spanEvent = trace.storage.storage[2] + t.equal(actualMethodDescriptor.apiId, spanEvent.apiId, 'apiId') + t.equal(spanEvent.annotations[0].key, -1, 'parameter') + t.equal(spanEvent.annotations[0].value.stringValue, '/express4', 'parameter value matching') + t.true(actualMethodDescriptor.apiDescriptor.startsWith('express.Function.app.get(path, callback)'), 'apiDescriptor') + t.equal(actualMethodDescriptor.className, 'Function', 'className') + t.equal(actualMethodDescriptor.fullName, 'express.app.get(path, callback)', 'fullName') + t.equal(actualMethodDescriptor.lineNumber, 481, 'lineNumber') + t.equal(actualMethodDescriptor.methodName, 'get', 'methodName') + t.equal(actualMethodDescriptor.moduleName, 'express', 'moduleName') + t.equal(actualMethodDescriptor.objectPath, 'app.get', 'objectPath') + t.true(actualMethodDescriptor.location.endsWith('application.js'), 'location') + t.equal(spanEvent.sequence, 0, 'sequence') + t.equal(spanEvent.depth, 1, 'spanEvent.depth') + + actualBuilder = new MethodDescriptorBuilder(undefined, '') + .setLineNumber(157) + .setFileName('express.test.js') + const actualHandlerMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder) + spanEvent = trace.storage.storage[1] + t.equal(spanEvent.sequence, 1, 'sequence') + t.equal(spanEvent.depth, 2, 'spanEvent.depth') + t.equal(actualHandlerMethodDescriptor.apiId, spanEvent.apiId, 'apiId') + t.equal(actualHandlerMethodDescriptor.apiDescriptor, 'Test.()', 'apiInfo') + t.equal(actualHandlerMethodDescriptor.type, 0, 'type') + t.equal(actualHandlerMethodDescriptor.lineNumber, 157, 'line number') + t.true(actualHandlerMethodDescriptor.location.endsWith('express.test.js'), 'location') + + spanEvent = trace.storage.storage[0] + t.equal(spanEvent.sequence, 2, 'sequence') + t.equal(spanEvent.depth, 3, 'spanEvent.depth') + t.equal(spanEvent.exceptionInfo.intValue, 1, 'error value') + t.true(spanEvent.exceptionInfo.stringValue.endsWith('express.test.js:160:10'), 'error case') +} + const testName2 = 'express2' test(`[${testName2}] Should record request in express.Router`, function (t) { agent.bindHttp() @@ -231,7 +335,7 @@ test(`[${testName2}] Should record request in express.Router`, function (t) { }) }) - +/* const testName3 = 'express3' test(`${testName3} Should record request taking more than 2 sec`, function (t) { agent.bindHttp() @@ -416,4 +520,4 @@ test('express version check', (t) => { actual = hook(null, '5.0.0', expected) t.equal(actual.name, 'module', 'express version 5.0.0 test') t.end() -}) \ No newline at end of file +}) diff --git a/test/instrumentation/module/fix-redis.test.js b/test/instrumentation/module/fix-redis.test.js index 0265068a..4b337711 100644 --- a/test/instrumentation/module/fix-redis.test.js +++ b/test/instrumentation/module/fix-redis.test.js @@ -23,7 +23,7 @@ test(`redis destination id`, async (t) => { const client = redis.createClient( container.getMappedPort(6379), - container.getContainerIpAddress(), + container.getHost(), ) client.on("error", function (error) { @@ -65,7 +65,7 @@ test("ioredis destination id", async function (t) { const port = container.getMappedPort(6379) const redis = new Redis( port, - container.getContainerIpAddress(), + container.getHost(), ) redis.on("error", function (error) { console.error(error) @@ -119,7 +119,7 @@ test(`Fix app crash without callback function https://github.com/pinpoint-apm/pi const redis = require('redis') const client = redis.createClient({ - host: container.getContainerIpAddress(), + host: container.getHost(), port: container.getMappedPort(6379), db: 3, }) diff --git a/test/instrumentation/module/http.test.js b/test/instrumentation/module/http.test.js index 1f5265da..d140e7ef 100644 --- a/test/instrumentation/module/http.test.js +++ b/test/instrumentation/module/http.test.js @@ -23,9 +23,9 @@ test(`outgoing request URL escape a bug`, async (t) => { t.true(agent.dataSender.mockSpanChunk.spanEventList.length == 2, `spanEventList`) const spanEvent = agent.dataSender.mockSpanChunk.spanEventList[1] - + t.equal(spanEvent.annotations[0].value.stringValue, "GET", "URL") - t.equal(spanEvent.annotations[1].value.stringValue, "eonet.sci.gsfc.nasa.gov/api/v2.1/categories", "URL") + t.equal(spanEvent.annotations[1].value.stringValue, "eonet.gsfc.nasa.gov/api/v2.1/categories", "URL") agent.completeTraceObject(trace) }) }) \ No newline at end of file diff --git a/test/instrumentation/module/mongodb-core.test.js b/test/instrumentation/module/mongodb-core.test.js index 9a0a7ca6..33a28ebf 100644 --- a/test/instrumentation/module/mongodb-core.test.js +++ b/test/instrumentation/module/mongodb-core.test.js @@ -19,7 +19,7 @@ test(`mongodb`, async (t) => { const trace = agent.createTraceObject() const Server = require('mongodb-core').Server var server = new Server({ - host: container.getContainerIpAddress(), + host: container.getHost(), port: container.getMappedPort(27017), reconnect: true, reconnectInterval: 50 @@ -44,27 +44,27 @@ test(`mongodb`, async (t) => { }, ordered: true }, async function (err, results) { - t.equal(null, err); - t.equal(2, results.result.n); + t.equal(null, err) + t.equal(2, results.result.n) server.destroy() await container.stop() agent.completeTraceObject(trace) t.end() - }); - }); - }); + }) + }) + }) server.on('close', function () { console.log('mongodb-core.test.js closed') t.end() - }); + }) server.on('reconnect', function () { - console.log('mongodb-core.test.js reconnect'); - }); + console.log('mongodb-core.test.js reconnect') + }) // Start connection - server.connect(); + server.connect() }) \ No newline at end of file