Skip to content

Commit

Permalink
wip fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
svetlanabrennan committed Oct 11, 2024
1 parent 929ec1c commit 269ab96
Showing 1 changed file with 131 additions and 122 deletions.
253 changes: 131 additions & 122 deletions test/unit/transaction/trace/segment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ test('TraceSegment', async (t) => {

// await t.test('should be bound to a Trace', (t) => {
// const { agent } = t.nr
// // agent.config.loggging.diagnostic = true
// let segment = null
// const trans = new Transaction(agent)
// assert.throws(function noTrace() {
Expand Down Expand Up @@ -301,6 +300,8 @@ test('with children created from URLs', async (t) => {

trace.end()
ctx.nr.webChild = webChild

ctx.nr.transaction = transaction
})

t.afterEach(afterEach)
Expand Down Expand Up @@ -332,23 +333,22 @@ test('with children created from URLs', async (t) => {
assert.equal(webChild.getAttributes()['request.parameters.test4'], '')
})

// // TODO: pass transaction to toJson
// // await t.test('should serialize the segment with the parameters', (t) => {
// // const { webChild } = t.nr
// // assert.deepEqual(webChild.toJSON(), [
// // 0,
// // 1,
// // 'WebTransaction/NormalizedUri/*',
// // {
// // 'nr_exclusive_duration_millis': 1,
// // 'request.parameters.test1': 'value1',
// // 'request.parameters.test2': true,
// // 'request.parameters.test3': '50',
// // 'request.parameters.test4': ''
// // },
// // []
// // ])
// // })
await t.test('should serialize the segment with the parameters', (t) => {
const { webChild } = t.nr
assert.deepEqual(webChild.toJSON(t.nr.transaction), [
0,
1,
'WebTransaction/NormalizedUri/*',
{
'nr_exclusive_duration_millis': 1,
'request.parameters.test1': 'value1',
'request.parameters.test2': true,
'request.parameters.test3': '50',
'request.parameters.test4': ''
},
[]
])
})
})

test('with parameters parsed out by framework', async (t) => {
Expand Down Expand Up @@ -381,6 +381,7 @@ test('with parameters parsed out by framework', async (t) => {
trace.end()
ctx.nr.webChild = webChild
ctx.nr.trace = trace
ctx.nr.transaction = transaction
})
t.afterEach(afterEach)

Expand All @@ -406,23 +407,22 @@ test('with parameters parsed out by framework', async (t) => {
assert.equal(trace.attributes.get(DESTINATIONS.TRANS_TRACE)['test3'], '50')
})

// // TODO: pass transaction to toJson
// // await t.test('should serialize the segment with the parameters', (t) => {
// // const { webChild } = t.nr
// // const expected = [
// // 0,
// // 1,
// // 'WebTransaction/NormalizedUri/*',
// // {
// // nr_exclusive_duration_millis: 1,
// // 0: 'first',
// // 1: 'another',
// // test3: '50'
// // },
// // []
// // ]
// // assert.deepEqual(webChild.toJSON(), expected)
// // })
await t.test('should serialize the segment with the parameters', (t) => {
const { webChild } = t.nr
const expected = [
0,
1,
'WebTransaction/NormalizedUri/*',
{
nr_exclusive_duration_millis: 1,
0: 'first',
1: 'another',
test3: '50'
},
[]
]
assert.deepEqual(webChild.toJSON(t.nr.transaction), expected)
})
})

test('with attributes.enabled set to false', async (t) => {
Expand All @@ -443,6 +443,7 @@ test('with attributes.enabled set to false', async (t) => {
trace.setDurationInMillis(1, 0)
webChild.setDurationInMillis(1, 0)
ctx.nr.webChild = webChild
ctx.nr.transaction = transaction
})
t.afterEach(afterEach)

Expand All @@ -456,12 +457,11 @@ test('with attributes.enabled set to false', async (t) => {
assert.deepEqual(webChild.getAttributes(), {})
})

// TODO: add transaction to toJSON
// await t.test('should serialize the segment without the parameters', (t) => {
// const { webChild } = t.nr
// const expected = [0, 1, 'WebTransaction/NormalizedUri/*', {}, []]
// assert.deepEqual(webChild.toJSON(), expected)
// })
await t.test('should serialize the segment without the parameters', (t) => {
const { webChild } = t.nr
const expected = [0, 1, 'WebTransaction/NormalizedUri/*', {}, []]
assert.deepEqual(webChild.toJSON(t.nr.transaction), expected)
})
})

test('with attributes.enabled set', async (t) => {
Expand Down Expand Up @@ -490,6 +490,7 @@ test('with attributes.enabled set', async (t) => {
webChild.setDurationInMillis(1, 0)
ctx.nr.attributes = webChild.getAttributes()
ctx.nr.webChild = webChild
ctx.nr.transaction = transaction

trace.end()
})
Expand Down Expand Up @@ -523,54 +524,62 @@ test('with attributes.enabled set', async (t) => {
assert.equal(attributes['request.parameters.test2'], true)
})

// await t.test('should serialize the segment with the parameters', (t) => {
// const { webChild } = t.nr
// assert.deepEqual(webChild.toJSON(), [
// 0,
// 1,
// 'WebTransaction/NormalizedUri/*',
// {
// 'nr_exclusive_duration_millis': 1,
// 'request.parameters.test2': true,
// 'request.parameters.test3': '50'
// },
// []
// ])
// })
await t.test('should serialize the segment with the parameters', (t) => {
const { webChild } = t.nr
assert.deepEqual(webChild.toJSON(t.nr.transaction), [
0,
1,
'WebTransaction/NormalizedUri/*',
{
'nr_exclusive_duration_millis': 1,
'request.parameters.test2': true,
'request.parameters.test3': '50'
},
[]
])
})
})

test('when serialized', async (t) => {
t.beforeEach((ctx) => {
const agent = helper.loadMockedAgent()
const trans = new Transaction(agent)
const segment = new TraceSegment(agent.config, 'UnitTest', trans)
const segment = new TraceSegment(agent.config, 'UnitTest', true. transaction.traceStacks)

Check failure on line 547 in test/unit/transaction/trace/segment.test.js

View workflow job for this annotation

GitHub Actions / lint (lts/*)

Delete `·`
ctx.nr = {
agent,
agent: agent,
segment,
trans
}

ctx.nr.agent.config.logging.diagnostics = true


Check failure on line 556 in test/unit/transaction/trace/segment.test.js

View workflow job for this annotation

GitHub Actions / lint (lts/*)

Replace `⏎····ctx.nr.transaction·=·transaction⏎` with `····ctx.nr.transaction·=·transaction`
ctx.nr.transaction = transaction

Check failure on line 557 in test/unit/transaction/trace/segment.test.js

View workflow job for this annotation

GitHub Actions / lint (lts/*)

'transaction' is not defined


trace.end()

Check failure on line 560 in test/unit/transaction/trace/segment.test.js

View workflow job for this annotation

GitHub Actions / lint (lts/*)

'trace' is not defined
})

t.afterEach((ctx) => {
helper.unloadAgent(ctx.nr.agent)
})

// await t.test('should create a plain JS array', (t) => {
// const { segment } = t.nr
// segment.end()
// const js = segment.toJSON()
await t.test('should create a plain JS array', (t) => {
const { segment } = t.nr
segment.end()
const js = segment.toJSON(t.nr.transaction)

// assert.ok(Array.isArray(js))
// assert.equal(typeof js[0], 'number')
// assert.equal(typeof js[1], 'number')
assert.ok(Array.isArray(js))
assert.equal(typeof js[0], 'number')
assert.equal(typeof js[1], 'number')

// assert.equal(js[2], 'UnitTest')
assert.equal(js[2], 'UnitTest')

// assert.equal(typeof js[3], 'object')
assert.equal(typeof js[3], 'object')

// assert.ok(Array.isArray(js[4]))
// assert.equal(js[4].length, 0)
// })
assert.ok(Array.isArray(js[4]))
assert.equal(js[4].length, 0)
})

// await t.test('should not cause a stack overflow', { timeout: 30000 }, (t) => {
// const { segment, trans, agent } = t.nr
Expand All @@ -582,60 +591,60 @@ test('when serialized', async (t) => {
// }

// assert.doesNotThrow(function () {
// segment.toJSON()
// segment.toJSON(t.nr.trans)
// })
// })
})

test('getSpanContext', async (t) => {
t.beforeEach((ctx) => {
const agent = helper.loadMockedAgent({
distributed_tracing: {
enabled: true
}
})
const transaction = new Transaction(agent)
const segment = new TraceSegment(agent.config, 'UnitTest', transaction)
ctx.nr = {
agent,
segment,
transaction
}
})

t.afterEach((ctx) => {
helper.unloadAgent(ctx.nr.agent)
})

await t.test('should not initialize with a span context', (t) => {
const { segment } = t.nr
assert.ok(!segment._spanContext)
})

await t.test('should create a new context when empty', (t) => {
const { segment } = t.nr
const spanContext = segment.getSpanContext()
assert.ok(spanContext)
})

await t.test('should not create a new context when empty and DT disabled', (t) => {
const { agent, segment } = t.nr
agent.config.distributed_tracing.enabled = false
const spanContext = segment.getSpanContext()
assert.ok(!spanContext)
})

await t.test('should not create a new context when empty and Spans disabled', (t) => {
const { agent, segment } = t.nr
agent.config.span_events.enabled = false
const spanContext = segment.getSpanContext()
assert.ok(!spanContext)
})

await t.test('should return existing span context', (t) => {
const { segment } = t.nr
const originalContext = segment.getSpanContext()
const secondContext = segment.getSpanContext()
assert.equal(originalContext, secondContext)
})
})
// test('getSpanContext', async (t) => {
// t.beforeEach((ctx) => {
// const agent = helper.loadMockedAgent({
// distributed_tracing: {
// enabled: true
// }
// })
// const transaction = new Transaction(agent)
// const segment = new TraceSegment(agent.config, 'UnitTest', true, transaction.traceStacks)
// ctx.nr = {
// agent,
// segment,
// transaction
// }
// })

// t.afterEach((ctx) => {
// helper.unloadAgent(ctx.nr.agent)
// })

// await t.test('should not initialize with a span context', (t) => {
// const { segment } = t.nr
// assert.ok(!segment._spanContext)
// })

// await t.test('should create a new context when empty', (t) => {
// const { segment } = t.nr
// const spanContext = segment.getSpanContext()
// assert.ok(spanContext)
// })

// await t.test('should not create a new context when empty and DT disabled', (t) => {
// const { agent, segment } = t.nr
// agent.config.distributed_tracing.enabled = false
// const spanContext = segment.getSpanContext()
// assert.ok(!spanContext)
// })

// await t.test('should not create a new context when empty and Spans disabled', (t) => {
// const { agent, segment } = t.nr
// agent.config.span_events.enabled = false
// const spanContext = segment.getSpanContext()
// assert.ok(!spanContext)
// })

// await t.test('should return existing span context', (t) => {
// const { segment } = t.nr
// const originalContext = segment.getSpanContext()
// const secondContext = segment.getSpanContext()
// assert.equal(originalContext, secondContext)
// })
// })

0 comments on commit 269ab96

Please sign in to comment.