66
77const test = require ( 'tape' )
88const axios = require ( 'axios' )
9- const { fixture, util } = require ( '../test-helper' )
10- const activeTrace = require ( '../../lib/metric/active-trace' )
119const agent = require ( '../support/agent-singleton-mock' )
1210const express = require ( 'express' )
1311const http = require ( 'http' )
1412const grpc = require ( '@grpc/grpc-js' )
1513const services = require ( '../../lib/data/v1/Service_grpc_pb' )
1614const spanMessages = require ( '../../lib/data/v1/Span_pb' )
15+ const activeRequestRepository = require ( '../../lib/metric/active-request-repository' )
1716
1817const TEST_ENV = {
1918 host : 'localhost' ,
2019 port : 5005 ,
2120}
2221const getServerUrl = ( path ) => `http://${ TEST_ENV . host } :${ TEST_ENV . port } ${ path } `
2322
24- test ( `Should record active trace in multiple call` , function ( t ) {
25- agent . bindHttp ( )
26-
27- const PATH = '/active-trace'
28- const LASTONE_PATH = '/active-trace/lastone'
29- const SHUTDOWN = '/shutdown'
30- const app = new express ( )
31-
32- app . get ( PATH , async ( req , res ) => {
33- await util . sleep ( 2000 )
34- res . send ( 'ok get' )
35- } )
36-
37- app . get ( LASTONE_PATH , async ( req , res ) => {
38- res . send ( 'ok get' )
39- } )
40-
41- const server = app . listen ( TEST_ENV . port , async function ( ) {
42- Promise . all ( [
43- axios . get ( getServerUrl ( PATH ) , { httpAgent : new http . Agent ( { keepAlive : false } ) } ) ,
44- axios . get ( getServerUrl ( PATH ) , { httpAgent : new http . Agent ( { keepAlive : false } ) } ) ,
45- axios . get ( getServerUrl ( LASTONE_PATH ) , { httpAgent : new http . Agent ( { keepAlive : false } ) } ) ,
46- ] ) . then ( ( result ) => {
47- t . equal ( activeTrace . getAllTraces ( ) . length , 0 )
48- t . equal ( '' + agent . mockAgentStartTime , agent . agentInfo . startTimestamp , "startTimestamp equals" )
49-
50- server . close ( )
51- t . end ( )
52- } ) . catch ( ( ) => {
53- server . close ( )
54- t . end ( )
55- } )
56- } )
57-
58- t . equal ( agent . mockAgentId , fixture . config . agentId , "Agent ID equals" )
59- t . equal ( agent . agentInfo , agent . pinpointClient . agentInfo , "AgentInfo equals" )
60- } )
61-
6223test ( `Active trace should be recorded with HTTP call` , function ( t ) {
6324 const collectorServer = new grpc . Server ( )
6425 collectorServer . addService ( services . MetadataService , {
@@ -73,7 +34,7 @@ test(`Active trace should be recorded with HTTP call`, function (t) {
7334 const app = new express ( )
7435 app . get ( '/active-trace' , async ( req , res ) => {
7536 agent . callbackTraceClose ( ( trace ) => {
76- const actualCached = agent . getTraceContext ( ) . activeRequestRepository . activeTraceCache . get ( trace . getTraceRoot ( ) . getTransactionId ( ) )
37+ const actualCached = activeRequestRepository . activeTraceCache . get ( trace . getTraceRoot ( ) . getTransactionId ( ) )
7738 t . equal ( actualCached , trace . getTraceRoot ( ) , 'active trace traceRoot is cached' )
7839 } )
7940 setTimeout ( ( ) => {
@@ -85,7 +46,7 @@ test(`Active trace should be recorded with HTTP call`, function (t) {
8546 const result = await axios . get ( getServerUrl ( '/active-trace' ) , { httpAgent : new http . Agent ( { keepAlive : false } ) } )
8647 t . equal ( result . status , 200 , 'status code is 200' )
8748 server . close ( ( ) => {
88- const cacheSize = agent . getTraceContext ( ) . activeRequestRepository . activeTraceCache . cache . size
49+ const cacheSize = activeRequestRepository . activeTraceCache . cache . size
8950 t . equal ( cacheSize , 0 , 'active trace cache is empty' )
9051 t . end ( )
9152 } )
0 commit comments