From de6b611e16b031091d61b32599dd55861ee34179 Mon Sep 17 00:00:00 2001 From: Yongseok Kang Date: Thu, 10 Feb 2022 22:52:56 +0900 Subject: [PATCH] [#104] koa module MethodDescriptorBuilder --- test/instrumentation/module/koa.test.js | 14 +++++++++++++- test/support/agent-singleton-mock.js | 10 ++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/test/instrumentation/module/koa.test.js b/test/instrumentation/module/koa.test.js index 5cc0e08e..d191b348 100644 --- a/test/instrumentation/module/koa.test.js +++ b/test/instrumentation/module/koa.test.js @@ -12,6 +12,9 @@ const agent = require('../../support/agent-singleton-mock') const Koa = require('koa') const Router = require('koa-router') +const apiMetaService = require('../../../lib/context/api-meta-service') +const MethodDescriptorBuilder = require('../../../lib/context/method-descriptor-builder') + const TEST_ENV = { host: 'localhost', port: 5006, @@ -20,6 +23,7 @@ const getServerUrl = (path) => `http://${TEST_ENV.host}:${TEST_ENV.port}${path}` const testName1 = 'koa-router1' test(`${testName1} Should record request in basic route koa.test.js`, function (t) { + agent.bindHttp() const testName = testName1 t.plan(3) @@ -30,7 +34,15 @@ test(`${testName1} Should record request in basic route koa.test.js`, function ( router.get(PATH, async (ctx, next) => { ctx.body = 'ok. get' - const trace = agent.traceContext.currentTraceObject() + + agent.callbackTraceClose((trace) => { + let actualBuilder = new MethodDescriptorBuilder('koa', 'get') + .setParameterDescriptor('(ctx, next)') + .setLineNumber(35) + .setFileName('koa.test.js') + const actualMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder) + let spanEvent = trace.storage.storage[0] + }) }) router.post(PATH, async (ctx, next) => { ctx.body = 'ok. post' diff --git a/test/support/agent-singleton-mock.js b/test/support/agent-singleton-mock.js index 6a851904..8ac613da 100644 --- a/test/support/agent-singleton-mock.js +++ b/test/support/agent-singleton-mock.js @@ -77,9 +77,15 @@ class MockAgent extends Agent { shimmer.unwrap(http, 'request') } - resetAgent(callback) { - this.pinpointClient = new MockPinpointClient(this.config, this.agentInfo, this.dataSender) + callbackTraceClose(callback) { + const trace = this.traceContext.currentTraceObject() + const origin = trace.close + trace.close = () => { + callback(trace) + origin.apply(trace, arguments) + } } + } const agent = new MockAgent(fixture.config)