Skip to content

Commit

Permalink
[#104] koa module MethodDescriptorBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
feelform committed Feb 11, 2022
1 parent a3ec75a commit de6b611
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
14 changes: 13 additions & 1 deletion test/instrumentation/module/koa.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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'
Expand Down
10 changes: 8 additions & 2 deletions test/support/agent-singleton-mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit de6b611

Please sign in to comment.