Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
bengl committed Jun 17, 2024
1 parent 95948d8 commit 077923f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
30 changes: 23 additions & 7 deletions integration-tests/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,22 +341,38 @@ function telemetryForwarder (expectedTelemetryPoints) {

let retries = 0

const tryAgain = async function () {
retries += 1
await new Promise(resolve => setTimeout(resolve, 100))
return cleanup()
}

const cleanup = async function () {
let msgs
try {
msgs = (await fs.readFile(process.env.FORWARDER_OUT, 'utf8')).trim().split('\n')
} catch (e) {
if (expectedTelemetryPoints.length && e.code === 'ENOENT' && retries < 10) {
retries += 1
await new Promise(resolve => setTimeout(resolve, 100))
return cleanup()
return tryAgain()
}
return []
}
msgs = msgs.map(msg => {
const [telemetryType, data] = msg.split('\t')
return [telemetryType, JSON.parse(data)]
})
for (let i = 0; i < msgs.length; i++) {
const [telemetryType, data] = msgs[i].split('\t')
if (!data && retries < 10) {
return tryAgain()
}
let parsed
try {
parsed = JSON.parse(data)

Check failure on line 367 in integration-tests/helpers.js

View workflow job for this annotation

GitHub Actions / lint

'parsed' is assigned a value but never used
} catch (e) {
if (!data && retries < 10) {
return tryAgain()
}
throw new SyntaxError(`error parsing data: ${e.message}\n${data}`)
}
msgs[i] = [telemetryType, JSON.parse(data)]
}
await fs.unlink(process.env.FORWARDER_OUT)
delete process.env.FORWARDER_OUT
delete process.env.DD_TELEMETRY_FORWARDER_PATH
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/init.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ true
})
}

describe('init.js', () => {
describe.only('init.js', () => {

Check warning on line 127 in integration-tests/init.spec.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected exclusive mocha test
useSandbox()

testInjectionScenarios('require', 'init.js', false)
Expand Down
3 changes: 2 additions & 1 deletion packages/dd-trace/src/telemetry/init-telemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ function sendTelemetry (name, tags = []) {
stdio: 'pipe',
shell: true
})
proc.stdin.end(JSON.stringify({ metadata, points }))
const bytes = JSON.stringify({ metadata, points })
proc.stdin.end(bytes)
}

0 comments on commit 077923f

Please sign in to comment.