Skip to content

Commit 65a0cf3

Browse files
szegedibengl
authored andcommitted
Add a fake agent for code hotspots and timeline tests too. (#5667)
Otherwise remote config's futile attempts to connect to agent time out tests.
1 parent 1d91059 commit 65a0cf3

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

integration-tests/profiler/profiler.spec.js

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ class NetworkEventProcessor extends TimelineEventProcessor {
150150
}
151151
}
152152

153-
async function gatherNetworkTimelineEvents (cwd, scriptFilePath, eventType, args) {
154-
return gatherTimelineEvents(cwd, scriptFilePath, eventType, args, NetworkEventProcessor)
153+
async function gatherNetworkTimelineEvents (cwd, scriptFilePath, agentPort, eventType, args) {
154+
return gatherTimelineEvents(cwd, scriptFilePath, agentPort, eventType, args, NetworkEventProcessor)
155155
}
156156

157157
class FilesystemEventProcessor extends TimelineEventProcessor {
@@ -201,18 +201,19 @@ class FilesystemEventProcessor extends TimelineEventProcessor {
201201
}
202202
}
203203

204-
async function gatherFilesystemTimelineEvents (cwd, scriptFilePath) {
205-
return gatherTimelineEvents(cwd, scriptFilePath, 'fs', [], FilesystemEventProcessor)
204+
async function gatherFilesystemTimelineEvents (cwd, scriptFilePath, agentPort) {
205+
return gatherTimelineEvents(cwd, scriptFilePath, agentPort, 'fs', [], FilesystemEventProcessor)
206206
}
207207

208-
async function gatherTimelineEvents (cwd, scriptFilePath, eventType, args, Processor) {
208+
async function gatherTimelineEvents (cwd, scriptFilePath, agentPort, eventType, args, Processor) {
209209
const procStart = BigInt(Date.now() * 1000000)
210210
const proc = fork(path.join(cwd, scriptFilePath), args, {
211211
cwd,
212212
env: {
213213
DD_PROFILING_EXPORTERS: 'file',
214214
DD_PROFILING_ENABLED: 1,
215-
DD_INTERNAL_PROFILING_TIMELINE_SAMPLING_ENABLED: 0 // capture all events
215+
DD_INTERNAL_PROFILING_TIMELINE_SAMPLING_ENABLED: 0, // capture all events
216+
DD_TRACE_AGENT_PORT: agentPort
216217
}
217218
})
218219

@@ -312,6 +313,14 @@ describe('profiler', () => {
312313
await sandbox.remove()
313314
})
314315

316+
beforeEach(async () => {
317+
agent = await new FakeAgent().start()
318+
})
319+
320+
afterEach(async () => {
321+
await agent.stop()
322+
})
323+
315324
if (process.platform !== 'win32') {
316325
it('code hotspots and endpoint tracing works', async function () {
317326
// see comment on busyCycleTimeNs recomputation below. Ideally a single retry should be enough
@@ -323,7 +332,8 @@ describe('profiler', () => {
323332
env: {
324333
DD_PROFILING_EXPORTERS: 'file',
325334
DD_PROFILING_ENABLED: 1,
326-
BUSY_CYCLE_TIME: (busyCycleTimeNs | 0).toString()
335+
BUSY_CYCLE_TIME: (busyCycleTimeNs | 0).toString(),
336+
DD_TRACE_AGENT_PORT: agent.port
327337
}
328338
})
329339

@@ -440,7 +450,7 @@ describe('profiler', () => {
440450
})
441451

442452
it('fs timeline events work', async () => {
443-
const fsEvents = await gatherFilesystemTimelineEvents(cwd, 'profiler/fstest.js')
453+
const fsEvents = await gatherFilesystemTimelineEvents(cwd, 'profiler/fstest.js', agent.port)
444454
assert.equal(fsEvents.length, 6)
445455
const path = fsEvents[0].path
446456
const fd = fsEvents[1].fd
@@ -456,7 +466,7 @@ describe('profiler', () => {
456466
})
457467

458468
it('dns timeline events work', async () => {
459-
const dnsEvents = await gatherNetworkTimelineEvents(cwd, 'profiler/dnstest.js', 'dns')
469+
const dnsEvents = await gatherNetworkTimelineEvents(cwd, 'profiler/dnstest.js', agent.port, 'dns')
460470
assert.sameDeepMembers(dnsEvents, [
461471
{ operation: 'lookup', host: 'example.org' },
462472
{ operation: 'lookup', host: 'example.com' },
@@ -494,7 +504,7 @@ describe('profiler', () => {
494504
const args = [String(port1), String(port2), msg]
495505
// Invoke the profiled program, passing it the ports of the servers and
496506
// the expected message.
497-
const events = await gatherNetworkTimelineEvents(cwd, 'profiler/nettest.js', 'net', args)
507+
const events = await gatherNetworkTimelineEvents(cwd, 'profiler/nettest.js', agent.port, 'net', args)
498508
// The profiled program should have two TCP connection events to the two
499509
// servers.
500510
assert.sameDeepMembers(events, [
@@ -511,8 +521,7 @@ describe('profiler', () => {
511521
}
512522

513523
context('shutdown', () => {
514-
beforeEach(async () => {
515-
agent = await new FakeAgent().start()
524+
beforeEach(() => {
516525
oomEnv = {
517526
DD_TRACE_AGENT_PORT: agent.port,
518527
DD_PROFILING_ENABLED: 1,
@@ -521,9 +530,8 @@ describe('profiler', () => {
521530
}
522531
})
523532

524-
afterEach(async () => {
533+
afterEach(() => {
525534
proc.kill()
526-
await agent.stop()
527535
})
528536

529537
it('records profile on process exit', () => {
@@ -641,13 +649,8 @@ describe('profiler', () => {
641649
})
642650

643651
context('SSI heuristics', () => {
644-
beforeEach(async () => {
645-
agent = await new FakeAgent().start()
646-
})
647-
648-
afterEach(async () => {
652+
afterEach(() => {
649653
proc.kill()
650-
await agent.stop()
651654
})
652655

653656
describe('does not trigger for', () => {

0 commit comments

Comments
 (0)