Skip to content

[test-optimization] [SDTEST-2163] Check framework version in capabilities tagging #5876

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

Merged
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
18 changes: 13 additions & 5 deletions integration-tests/playwright/playwright.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1363,12 +1363,20 @@ versions.forEach((version) => {
assert.isNotEmpty(metadataDicts)
metadataDicts.forEach(metadata => {
assert.equal(metadata.test[DD_CAPABILITIES_TEST_IMPACT_ANALYSIS], undefined)
assert.equal(metadata.test[DD_CAPABILITIES_EARLY_FLAKE_DETECTION], '1')
assert.equal(metadata.test[DD_CAPABILITIES_AUTO_TEST_RETRIES], '1')
assert.equal(metadata.test[DD_CAPABILITIES_IMPACTED_TESTS], '1')
assert.equal(metadata.test[DD_CAPABILITIES_TEST_MANAGEMENT_QUARANTINE], '1')
assert.equal(metadata.test[DD_CAPABILITIES_TEST_MANAGEMENT_DISABLE], '1')
assert.equal(metadata.test[DD_CAPABILITIES_TEST_MANAGEMENT_ATTEMPT_TO_FIX], '4')
if (satisfies(version, '>=1.38.0') || version === 'latest') {
assert.equal(metadata.test[DD_CAPABILITIES_EARLY_FLAKE_DETECTION], '1')
assert.equal(metadata.test[DD_CAPABILITIES_IMPACTED_TESTS], '1')
assert.equal(metadata.test[DD_CAPABILITIES_TEST_MANAGEMENT_QUARANTINE], '1')
assert.equal(metadata.test[DD_CAPABILITIES_TEST_MANAGEMENT_DISABLE], '1')
assert.equal(metadata.test[DD_CAPABILITIES_TEST_MANAGEMENT_ATTEMPT_TO_FIX], '4')
} else {
assert.equal(metadata.test[DD_CAPABILITIES_EARLY_FLAKE_DETECTION], undefined)
assert.equal(metadata.test[DD_CAPABILITIES_IMPACTED_TESTS], undefined)
assert.equal(metadata.test[DD_CAPABILITIES_TEST_MANAGEMENT_QUARANTINE], undefined)
assert.equal(metadata.test[DD_CAPABILITIES_TEST_MANAGEMENT_DISABLE], undefined)
assert.equal(metadata.test[DD_CAPABILITIES_TEST_MANAGEMENT_ATTEMPT_TO_FIX], undefined)
}
// capabilities logic does not overwrite test session name
assert.equal(metadata.test[TEST_SESSION_NAME], 'my-test-session-name')
})
Expand Down
6 changes: 3 additions & 3 deletions packages/datadog-instrumentations/src/cucumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ function getErrorFromCucumberResult (cucumberResult) {
return error
}

function getChannelPromise (channelToPublishTo, isParallel = false) {
function getChannelPromise (channelToPublishTo, isParallel = false, frameworkVersion = null) {
return new Promise(resolve => {
channelToPublishTo.publish({ onDone: resolve, isParallel })
channelToPublishTo.publish({ onDone: resolve, isParallel, frameworkVersion })
})
}

Expand Down Expand Up @@ -451,7 +451,7 @@ function getWrappedStart (start, frameworkVersion, isParallel = false, isCoordin
}
let errorSkippableRequest

const configurationResponse = await getChannelPromise(libraryConfigurationCh, isParallel)
const configurationResponse = await getChannelPromise(libraryConfigurationCh, isParallel, frameworkVersion)

isEarlyFlakeDetectionEnabled = configurationResponse.libraryConfig?.isEarlyFlakeDetectionEnabled
earlyFlakeDetectionNumRetries = configurationResponse.libraryConfig?.earlyFlakeDetectionNumRetries
Expand Down
2 changes: 1 addition & 1 deletion packages/datadog-instrumentations/src/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ function getCliWrapper (isNewJestVersion) {
return runCLI.apply(this, arguments)
}

libraryConfigurationCh.publish({ onDone })
libraryConfigurationCh.publish({ onDone, frameworkVersion: jestVersion })

try {
const { err, libraryConfig } = await configurationPromise
Expand Down
11 changes: 6 additions & 5 deletions packages/datadog-instrumentations/src/mocha/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,10 @@ function getOnEndHandler (isParallel) {
}
}

function getExecutionConfiguration (runner, isParallel, onFinishRequest) {
function getExecutionConfiguration (runner, isParallel, frameworkVersion, onFinishRequest) {
const ctx = {
isParallel
isParallel,
frameworkVersion
}

const onReceivedSkippableSuites = ({ err, skippableSuites, itrCorrelationId: responseItrCorrelationId }) => {
Expand Down Expand Up @@ -343,7 +344,7 @@ addHook({
name: 'mocha',
versions: ['>=5.2.0'],
file: 'lib/mocha.js'
}, (Mocha) => {
}, (Mocha, frameworkVersion) => {
shimmer.wrap(Mocha.prototype, 'run', run => function () {
// Workers do not need to request any data, just run the tests
if (!testFinishCh.hasSubscribers || getEnvironmentVariable('MOCHA_WORKER_ID') || this.options.parallel) {
Expand All @@ -363,7 +364,7 @@ addHook({
}
})

getExecutionConfiguration(runner, false, () => {
getExecutionConfiguration(runner, false, frameworkVersion, () => {
if (config.isKnownTestsEnabled) {
const testSuites = this.files.map(file => getTestSuitePath(file, process.cwd()))
const isFaulty = getIsFaultyEarlyFlakeDetection(
Expand Down Expand Up @@ -616,7 +617,7 @@ addHook({
this.once('start', getOnStartHandler(true, frameworkVersion))
this.once('end', getOnEndHandler(true))

getExecutionConfiguration(this, true, () => {
getExecutionConfiguration(this, true, frameworkVersion, () => {
if (config.isKnownTestsEnabled) {
const testSuites = files.map(file => getTestSuitePath(file, process.cwd()))
const isFaulty = getIsFaultyEarlyFlakeDetection(
Expand Down
5 changes: 4 additions & 1 deletion packages/datadog-instrumentations/src/playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,10 @@ function runnerHook (runnerExport, playwrightVersion) {
testSessionStartCh.publish({ command, frameworkVersion: playwrightVersion, rootDir })

try {
const { err, libraryConfig } = await getChannelPromise(libraryConfigurationCh)
const { err, libraryConfig } = await getChannelPromise(
libraryConfigurationCh,
{ frameworkVersion: playwrightVersion }
)
if (!err) {
isKnownTestsEnabled = libraryConfig.isKnownTestsEnabled
isEarlyFlakeDetectionEnabled = libraryConfig.isEarlyFlakeDetectionEnabled
Expand Down
8 changes: 4 additions & 4 deletions packages/datadog-instrumentations/src/vitest.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ function isBaseSequencer (vitestPackage) {
return vitestPackage.b?.name === 'BaseSequencer'
}

function getChannelPromise (channelToPublishTo) {
function getChannelPromise (channelToPublishTo, frameworkVersion) {
return new Promise(resolve => {
channelToPublishTo.publish({ onDone: resolve })
channelToPublishTo.publish({ onDone: resolve, frameworkVersion })
})
}

Expand Down Expand Up @@ -173,7 +173,7 @@ function getTestName (task) {
return testName
}

function getSortWrapper (sort) {
function getSortWrapper (sort, frameworkVersion) {
return async function () {
if (!testSessionFinishCh.hasSubscribers) {
return sort.apply(this, arguments)
Expand All @@ -193,7 +193,7 @@ function getSortWrapper (sort) {
let isDiEnabled = false

try {
const { err, libraryConfig } = await getChannelPromise(libraryConfigurationCh)
const { err, libraryConfig } = await getChannelPromise(libraryConfigurationCh, frameworkVersion)
if (!err) {
isFlakyTestRetriesEnabled = libraryConfig.isFlakyTestRetriesEnabled
flakyTestRetriesCount = libraryConfig.flakyTestRetriesCount
Expand Down
2 changes: 1 addition & 1 deletion packages/datadog-plugin-cypress/src/cypress-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ class CypressPlugin {
[TEST_SESSION_NAME]: testSessionName
}
}
const libraryCapabilitiesTags = getLibraryCapabilitiesTags(this.constructor.id)
const libraryCapabilitiesTags = getLibraryCapabilitiesTags(this.constructor.id, false, this.frameworkVersion)
metadataTags.test = {
...metadataTags.test,
...libraryCapabilitiesTags
Expand Down
4 changes: 2 additions & 2 deletions packages/dd-trace/src/plugins/ci_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ module.exports = class CiPlugin extends Plugin {
this.rootDir = process.cwd() // fallback in case :session:start events are not emitted

this.addSub(`ci:${this.constructor.id}:library-configuration`, (ctx) => {
const { onDone, isParallel } = ctx
const { onDone, isParallel, frameworkVersion } = ctx
ctx.currentStore = storage('legacy').getStore()

if (!this.tracer._exporter || !this.tracer._exporter.getLibraryConfiguration) {
Expand All @@ -88,7 +88,7 @@ module.exports = class CiPlugin extends Plugin {
this.libraryConfig = libraryConfig
}

const libraryCapabilitiesTags = getLibraryCapabilitiesTags(this.constructor.id, isParallel)
const libraryCapabilitiesTags = getLibraryCapabilitiesTags(this.constructor.id, isParallel, frameworkVersion)
const metadataTags = {
test: {
...libraryCapabilitiesTags
Expand Down
59 changes: 53 additions & 6 deletions packages/dd-trace/src/plugins/util/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const fs = require('fs')
const { URL } = require('url')
const log = require('../../log')
const { getEnvironmentVariable } = require('../../config-helper')
const satisfies = require('semifies')

const istanbul = require('istanbul-lib-coverage')
const ignore = require('ignore')
Expand Down Expand Up @@ -129,6 +130,18 @@ const DD_CAPABILITIES_TEST_MANAGEMENT_DISABLE = '_dd.library_capabilities.test_m
const DD_CAPABILITIES_TEST_MANAGEMENT_ATTEMPT_TO_FIX = '_dd.library_capabilities.test_management.attempt_to_fix'
const UNSUPPORTED_TIA_FRAMEWORKS = new Set(['playwright', 'vitest'])
const UNSUPPORTED_TIA_FRAMEWORKS_PARALLEL_MODE = new Set(['cucumber', 'mocha'])
const MINIMUM_FRAMEWORK_VERSION_FOR_EFD = {
playwright: '>=1.38.0'
}
const MINIMUM_FRAMEWORK_VERSION_FOR_IMPACTED_TESTS = {
playwright: '>=1.38.0'
}
const MINIMUM_FRAMEWORK_VERSION_FOR_QUARANTINE = {
playwright: '>=1.38.0'
}
const MINIMUM_FRAMEWORK_VERSION_FOR_DISABLE = {
playwright: '>=1.38.0'
}
const UNSUPPORTED_ATTEMPT_TO_FIX_FRAMEWORKS_PARALLEL_MODE = new Set(['mocha'])
const NOT_SUPPORTED_GRANULARITY_IMPACTED_TESTS_FRAMEWORKS = new Set(['mocha', 'playwright', 'vitest'])

Expand Down Expand Up @@ -895,18 +908,52 @@ function isTiaSupported (testFramework, isParallel) {
(isParallel && UNSUPPORTED_TIA_FRAMEWORKS_PARALLEL_MODE.has(testFramework)))
}

function isEarlyFlakeDetectionSupported (testFramework, frameworkVersion) {
return testFramework === 'playwright'
? satisfies(frameworkVersion, MINIMUM_FRAMEWORK_VERSION_FOR_EFD[testFramework])
: true
}

function isImpactedTestsSupported (testFramework, frameworkVersion) {
return testFramework === 'playwright'
? satisfies(frameworkVersion, MINIMUM_FRAMEWORK_VERSION_FOR_IMPACTED_TESTS[testFramework])
: true
}

function isQuarantineSupported (testFramework, frameworkVersion) {
return testFramework === 'playwright'
? satisfies(frameworkVersion, MINIMUM_FRAMEWORK_VERSION_FOR_QUARANTINE[testFramework])
: true
}

function isDisableSupported (testFramework, frameworkVersion) {
return testFramework === 'playwright'
? satisfies(frameworkVersion, MINIMUM_FRAMEWORK_VERSION_FOR_DISABLE[testFramework])
: true
}

function isAttemptToFixSupported (testFramework, isParallel) {
return !(isParallel && UNSUPPORTED_ATTEMPT_TO_FIX_FRAMEWORKS_PARALLEL_MODE.has(testFramework))
}

function getLibraryCapabilitiesTags (testFramework, isParallel) {
function getLibraryCapabilitiesTags (testFramework, isParallel, frameworkVersion) {
return {
[DD_CAPABILITIES_TEST_IMPACT_ANALYSIS]: isTiaSupported(testFramework, isParallel) ? '1' : undefined,
[DD_CAPABILITIES_EARLY_FLAKE_DETECTION]: '1',
[DD_CAPABILITIES_TEST_IMPACT_ANALYSIS]: isTiaSupported(testFramework, isParallel)
? '1'
: undefined,
[DD_CAPABILITIES_EARLY_FLAKE_DETECTION]: isEarlyFlakeDetectionSupported(testFramework, frameworkVersion)
? '1'
: undefined,
[DD_CAPABILITIES_AUTO_TEST_RETRIES]: '1',
[DD_CAPABILITIES_IMPACTED_TESTS]: '1',
[DD_CAPABILITIES_TEST_MANAGEMENT_QUARANTINE]: '1',
[DD_CAPABILITIES_TEST_MANAGEMENT_DISABLE]: '1',
[DD_CAPABILITIES_IMPACTED_TESTS]: isImpactedTestsSupported(testFramework, frameworkVersion)
? '1'
: undefined,
[DD_CAPABILITIES_TEST_MANAGEMENT_QUARANTINE]: isQuarantineSupported(testFramework, frameworkVersion)
? '1'
: undefined,
[DD_CAPABILITIES_TEST_MANAGEMENT_DISABLE]: isDisableSupported(testFramework, frameworkVersion)
? '1'
: undefined,
[DD_CAPABILITIES_TEST_MANAGEMENT_ATTEMPT_TO_FIX]: isAttemptToFixSupported(testFramework, isParallel)
? '4'
: undefined
Expand Down