Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(W-15263489): improve unit test performance #2716

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions packages/cli/src/global_telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ const {version} = require('../package.json')

const root = path.resolve(__dirname, '../package.json')
const isDev = process.env.IS_DEV_ENVIRONMENT === 'true'
const config = new Config({root})
const heroku = new APIClient(config)
const token = heroku.auth

function getToken() {
const config = new Config({root})
const heroku = new APIClient(config)
return heroku.auth
}

const debug = require('debug')('global_telemetry')

Expand Down Expand Up @@ -44,7 +47,7 @@ const provider = new NodeTracerProvider({
resource,
})

const headers = {Authorization: `Bearer ${token}`}
const headers = {Authorization: `Bearer ${process.env.IS_HEROKU_TEST_ENV !== 'true' ? getToken() : ''}`}

const exporter = new OTLPTraceExporter({
url: isDev ? 'https://backboard-staging.herokuapp.com/otel/v1/traces' : 'https://backboard.heroku.com/otel/v1/traces',
Expand Down
10 changes: 6 additions & 4 deletions packages/cli/src/hooks/postrun/performance_analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import * as telemetry from '../../global_telemetry'
declare const global: telemetry.TelemetryGlobal

const performance_analytics: Hook<'postrun'> = async function () {
if (global.cliTelemetry) {
const cmdStartTime = global.cliTelemetry.commandRunDuration
global.cliTelemetry.commandRunDuration = telemetry.computeDuration(cmdStartTime)
global.cliTelemetry.lifecycleHookCompletion.postrun = true
if (process.env.IS_HEROKU_TEST_ENV === 'true' || !global.cliTelemetry) {
return
}

const cmdStartTime = global.cliTelemetry.commandRunDuration
global.cliTelemetry.commandRunDuration = telemetry.computeDuration(cmdStartTime)
global.cliTelemetry.lifecycleHookCompletion.postrun = true
}

export default performance_analytics
4 changes: 4 additions & 0 deletions packages/cli/src/hooks/prerun/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import * as telemetry from '../../global_telemetry'
declare const global: telemetry.TelemetryGlobal

const analytics: Hook<'prerun'> = async function (options) {
if (process.env.IS_HEROKU_TEST_ENV === 'true') {
return
}

global.cliTelemetry = telemetry.setupTelemetry(this.config, options)
const analytics = new Analytics(this.config)
await analytics.record(options)
Expand Down
1 change: 0 additions & 1 deletion packages/cli/test/acceptance/smoke.acceptance.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// tslint:disable no-console

import * as fs from 'fs-extra'
import {expect} from 'chai'
import * as path from 'path'
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/test/helpers/init.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
const path = require('path')

globalThis.setInterval = () => ({unref: () => {}})
const tm = globalThis.setTimeout
globalThis.setTimeout = cb => {
return tm(cb)
}

process.env.TS_NODE_PROJECT = path.resolve('test/tsconfig.json')
process.env.IS_HEROKU_TEST_ENV = 'true'

let nock = require('nock')
nock.disableNetConnect()
Expand Down
Loading