Skip to content

Commit

Permalink
Revert "[test visibility] Use new metadata field in citestcycle (#4649)…
Browse files Browse the repository at this point in the history
…" (#4658)

This reverts commit 421f3d4.
  • Loading branch information
juan-fernandez committed Oct 1, 2024
1 parent f05454a commit 3082f59
Show file tree
Hide file tree
Showing 17 changed files with 99 additions and 181 deletions.
14 changes: 5 additions & 9 deletions integration-tests/cucumber/cucumber.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ const {
CUCUMBER_IS_PARALLEL,
TEST_SUITE,
TEST_CODE_OWNERS,
TEST_SESSION_NAME,
TEST_LEVEL_EVENT_TYPES
TEST_SESSION_NAME
} = require('../../packages/dd-trace/src/plugins/util/test')

const isOldNode = semver.satisfies(process.version, '<=16')
Expand Down Expand Up @@ -116,13 +115,6 @@ versions.forEach(version => {

const receiverPromise = receiver
.gatherPayloadsMaxTimeout(({ url }) => url.endsWith('/api/v2/citestcycle'), payloads => {
const metadataDicts = payloads.flatMap(({ payload }) => payload.metadata)
metadataDicts.forEach(metadata => {
for (const testLevel of TEST_LEVEL_EVENT_TYPES) {
assert.equal(metadata[testLevel][TEST_SESSION_NAME], 'my-test-session')
}
})

const events = payloads.flatMap(({ payload }) => payload.events)

const testSessionEvent = events.find(event => event.type === 'test_session_end')
Expand All @@ -139,12 +131,14 @@ versions.forEach(version => {
assert.equal(testSessionEventContent.meta[CUCUMBER_IS_PARALLEL], 'true')
}

assert.equal(testSessionEventContent.meta[TEST_SESSION_NAME], 'my-test-session')
assert.exists(testSessionEventContent.test_session_id)
assert.exists(testSessionEventContent.meta[TEST_COMMAND])
assert.exists(testSessionEventContent.meta[TEST_TOOLCHAIN])
assert.equal(testSessionEventContent.resource.startsWith('test_session.'), true)
assert.equal(testSessionEventContent.meta[TEST_STATUS], 'fail')

assert.equal(testModuleEventContent.meta[TEST_SESSION_NAME], 'my-test-session')
assert.exists(testModuleEventContent.test_session_id)
assert.exists(testModuleEventContent.test_module_id)
assert.exists(testModuleEventContent.meta[TEST_COMMAND])
Expand Down Expand Up @@ -173,6 +167,7 @@ versions.forEach(version => {
test_session_id: testSessionId
}
}) => {
assert.equal(meta[TEST_SESSION_NAME], 'my-test-session')
assert.exists(meta[TEST_COMMAND])
assert.exists(meta[TEST_MODULE])
assert.exists(testSuiteId)
Expand Down Expand Up @@ -203,6 +198,7 @@ versions.forEach(version => {
test_session_id: testSessionId
}
}) => {
assert.equal(meta[TEST_SESSION_NAME], 'my-test-session')
assert.exists(meta[TEST_COMMAND])
assert.exists(meta[TEST_MODULE])
assert.exists(testSuiteId)
Expand Down
14 changes: 5 additions & 9 deletions integration-tests/cypress/cypress.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ const {
TEST_EARLY_FLAKE_ENABLED,
TEST_SUITE,
TEST_CODE_OWNERS,
TEST_SESSION_NAME,
TEST_LEVEL_EVENT_TYPES
TEST_SESSION_NAME
} = require('../../packages/dd-trace/src/plugins/util/test')
const { ERROR_MESSAGE } = require('../../packages/dd-trace/src/constants')
const { NODE_MAJOR } = require('../../version')
Expand Down Expand Up @@ -227,13 +226,6 @@ moduleTypes.forEach(({
it('can run and report tests', (done) => {
const receiverPromise = receiver
.gatherPayloadsMaxTimeout(({ url }) => url.endsWith('/api/v2/citestcycle'), payloads => {
const metadataDicts = payloads.flatMap(({ payload }) => payload.metadata)

metadataDicts.forEach(metadata => {
for (const testLevel of TEST_LEVEL_EVENT_TYPES) {
assert.equal(metadata[testLevel][TEST_SESSION_NAME], 'my-test-session')
}
})
const events = payloads.flatMap(({ payload }) => payload.events)

const testSessionEvent = events.find(event => event.type === 'test_session_end')
Expand All @@ -244,12 +236,14 @@ moduleTypes.forEach(({
const { content: testSessionEventContent } = testSessionEvent
const { content: testModuleEventContent } = testModuleEvent

assert.equal(testSessionEventContent.meta[TEST_SESSION_NAME], 'my-test-session')
assert.exists(testSessionEventContent.test_session_id)
assert.exists(testSessionEventContent.meta[TEST_COMMAND])
assert.exists(testSessionEventContent.meta[TEST_TOOLCHAIN])
assert.equal(testSessionEventContent.resource.startsWith('test_session.'), true)
assert.equal(testSessionEventContent.meta[TEST_STATUS], 'fail')

assert.equal(testModuleEventContent.meta[TEST_SESSION_NAME], 'my-test-session')
assert.exists(testModuleEventContent.test_session_id)
assert.exists(testModuleEventContent.test_module_id)
assert.exists(testModuleEventContent.meta[TEST_COMMAND])
Expand Down Expand Up @@ -280,6 +274,7 @@ moduleTypes.forEach(({
test_session_id: testSessionId
}
}) => {
assert.equal(meta[TEST_SESSION_NAME], 'my-test-session')
assert.exists(meta[TEST_COMMAND])
assert.exists(meta[TEST_MODULE])
assert.exists(testSuiteId)
Expand Down Expand Up @@ -307,6 +302,7 @@ moduleTypes.forEach(({
test_session_id: testSessionId
}
}) => {
assert.equal(meta[TEST_SESSION_NAME], 'my-test-session')
assert.exists(meta[TEST_COMMAND])
assert.exists(meta[TEST_MODULE])
assert.exists(testSuiteId)
Expand Down
38 changes: 19 additions & 19 deletions integration-tests/jest/jest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ const {
TEST_EARLY_FLAKE_ABORT_REASON,
TEST_SOURCE_START,
TEST_CODE_OWNERS,
TEST_SESSION_NAME,
TEST_LEVEL_EVENT_TYPES
TEST_SESSION_NAME
} = require('../../packages/dd-trace/src/plugins/util/test')
const { ERROR_MESSAGE } = require('../../packages/dd-trace/src/constants')

Expand Down Expand Up @@ -135,14 +134,6 @@ describe('jest CommonJS', () => {
receiver.setInfoResponse({ endpoints: ['/evp_proxy/v4'] })
}
receiver.gatherPayloadsMaxTimeout(({ url }) => url.endsWith('citestcycle'), (payloads) => {
const metadataDicts = payloads.flatMap(({ payload }) => payload.metadata)

metadataDicts.forEach(metadata => {
for (const testLevel of TEST_LEVEL_EVENT_TYPES) {
assert.equal(metadata[testLevel][TEST_SESSION_NAME], 'my-test-session')
}
})

const events = payloads.flatMap(({ payload }) => payload.events)
const sessionEventContent = events.find(event => event.type === 'test_session_end').content
const moduleEventContent = events.find(event => event.type === 'test_module_end').content
Expand All @@ -159,18 +150,25 @@ describe('jest CommonJS', () => {
)
assert.equal(suites.length, 2)
assert.exists(sessionEventContent)
assert.equal(sessionEventContent.meta[TEST_SESSION_NAME], 'my-test-session')
assert.exists(moduleEventContent)
assert.equal(moduleEventContent.meta[TEST_SESSION_NAME], 'my-test-session')

assert.include(testOutput, expectedStdout)

tests.forEach(testEvent => {
assert.equal(testEvent.meta[TEST_SESSION_NAME], 'my-test-session')
assert.equal(testEvent.meta[TEST_SOURCE_FILE].startsWith('ci-visibility/test/ci-visibility-test'), true)
assert.exists(testEvent.metrics[TEST_SOURCE_START])
// Can read DD_TAGS
assert.propertyVal(testEvent.meta, 'test.customtag', 'customvalue')
assert.propertyVal(testEvent.meta, 'test.customtag2', 'customvalue2')
})

suites.forEach(testSuite => {
assert.equal(testSuite.meta[TEST_SESSION_NAME], 'my-test-session')
})

done()
})

Expand Down Expand Up @@ -443,19 +441,21 @@ describe('jest CommonJS', () => {
})

receiver.gatherPayloads(({ url }) => url === '/api/v2/citestcycle', 5000).then(eventsRequests => {
const metadataDicts = eventsRequests.flatMap(({ payload }) => payload.metadata)

// it propagates test session name to the test and test suite events in parallel mode
metadataDicts.forEach(metadata => {
for (const testLevel of TEST_LEVEL_EVENT_TYPES) {
assert.equal(metadata[testLevel][TEST_SESSION_NAME], 'my-test-session')
}
})

const events = eventsRequests.map(({ payload }) => payload)
.flatMap(({ events }) => events)
const eventTypes = events.map(event => event.type)

assert.includeMembers(eventTypes, ['test', 'test_suite_end', 'test_module_end', 'test_session_end'])
const tests = events.filter(event => event.type === 'test').map(event => event.content)
const testSuites = events.filter(event => event.type === 'test_suite_end').map(event => event.content)

// it propagates test session name to the test and test suite events in parallel mode
tests.forEach(testEvent => {
assert.equal(testEvent.meta[TEST_SESSION_NAME], 'my-test-session')
})
testSuites.forEach(testSuite => {
assert.equal(testSuite.meta[TEST_SESSION_NAME], 'my-test-session')
})

done()
}).catch(done)
Expand Down
28 changes: 10 additions & 18 deletions integration-tests/mocha/mocha.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ const {
MOCHA_IS_PARALLEL,
TEST_SOURCE_START,
TEST_CODE_OWNERS,
TEST_SESSION_NAME,
TEST_LEVEL_EVENT_TYPES
TEST_SESSION_NAME
} = require('../../packages/dd-trace/src/plugins/util/test')
const { ERROR_MESSAGE } = require('../../packages/dd-trace/src/constants')

Expand Down Expand Up @@ -134,14 +133,6 @@ describe('mocha CommonJS', function () {
receiver.setInfoResponse({ endpoints: ['/evp_proxy/v4'] })
}
receiver.gatherPayloadsMaxTimeout(({ url }) => url.endsWith('citestcycle'), (payloads) => {
const metadataDicts = payloads.flatMap(({ payload }) => payload.metadata)

metadataDicts.forEach(metadata => {
for (const testLevel of TEST_LEVEL_EVENT_TYPES) {
assert.equal(metadata[testLevel][TEST_SESSION_NAME], 'my-test-session')
}
})

const events = payloads.flatMap(({ payload }) => payload.events)
const sessionEventContent = events.find(event => event.type === 'test_session_end').content
const moduleEventContent = events.find(event => event.type === 'test_module_end').content
Expand All @@ -158,19 +149,26 @@ describe('mocha CommonJS', function () {
)
assert.equal(suites.length, 2)
assert.exists(sessionEventContent)
assert.equal(sessionEventContent.meta[TEST_SESSION_NAME], 'my-test-session')
assert.exists(moduleEventContent)
assert.equal(moduleEventContent.meta[TEST_SESSION_NAME], 'my-test-session')

assert.include(testOutput, expectedStdout)
assert.include(testOutput, extraStdout)

tests.forEach(testEvent => {
assert.equal(testEvent.meta[TEST_SESSION_NAME], 'my-test-session')
assert.equal(testEvent.meta[TEST_SOURCE_FILE].startsWith('ci-visibility/test/ci-visibility-test'), true)
assert.exists(testEvent.metrics[TEST_SOURCE_START])
// Can read DD_TAGS
assert.propertyVal(testEvent.meta, 'test.customtag', 'customvalue')
assert.propertyVal(testEvent.meta, 'test.customtag2', 'customvalue2')
})

suites.forEach(testSuite => {
assert.equal(testSuite.meta[TEST_SESSION_NAME], 'my-test-session')
})

done()
})

Expand Down Expand Up @@ -315,14 +313,6 @@ describe('mocha CommonJS', function () {
it('works with parallel mode', (done) => {
const eventsPromise = receiver
.gatherPayloadsMaxTimeout(({ url }) => url.endsWith('/api/v2/citestcycle'), (payloads) => {
const metadataDicts = payloads.flatMap(({ payload }) => payload.metadata)

metadataDicts.forEach(metadata => {
for (const testLevel of TEST_LEVEL_EVENT_TYPES) {
assert.equal(metadata[testLevel][TEST_SESSION_NAME], 'my-test-session')
}
})

const events = payloads.flatMap(({ payload }) => payload.events)
const sessionEventContent = events.find(event => event.type === 'test_session_end').content
const moduleEventContent = events.find(event => event.type === 'test_module_end').content
Expand All @@ -340,6 +330,7 @@ describe('mocha CommonJS', function () {
test_module_id: testModuleId,
test_session_id: testSessionId
}) => {
assert.equal(meta[TEST_SESSION_NAME], 'my-test-session')
assert.exists(meta[TEST_COMMAND])
assert.exists(meta[TEST_MODULE])
assert.exists(testSuiteId)
Expand All @@ -354,6 +345,7 @@ describe('mocha CommonJS', function () {
test_module_id: testModuleId,
test_session_id: testSessionId
}) => {
assert.equal(meta[TEST_SESSION_NAME], 'my-test-session')
assert.exists(meta[TEST_COMMAND])
assert.exists(meta[TEST_MODULE])
assert.exists(testSuiteId)
Expand Down
15 changes: 5 additions & 10 deletions integration-tests/playwright/playwright.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ const {
TEST_EARLY_FLAKE_ENABLED,
TEST_SUITE,
TEST_CODE_OWNERS,
TEST_SESSION_NAME,
TEST_LEVEL_EVENT_TYPES
TEST_SESSION_NAME
} = require('../../packages/dd-trace/src/plugins/util/test')
const { ERROR_MESSAGE } = require('../../packages/dd-trace/src/constants')

Expand Down Expand Up @@ -73,14 +72,6 @@ versions.forEach((version) => {
const reportUrl = reportMethod === 'agentless' ? '/api/v2/citestcycle' : '/evp_proxy/v2/api/v2/citestcycle'

receiver.gatherPayloadsMaxTimeout(({ url }) => url === reportUrl, payloads => {
const metadataDicts = payloads.flatMap(({ payload }) => payload.metadata)

metadataDicts.forEach(metadata => {
for (const testLevel of TEST_LEVEL_EVENT_TYPES) {
assert.equal(metadata[testLevel][TEST_SESSION_NAME], 'my-test-session')
}
})

const events = payloads.flatMap(({ payload }) => payload.events)

const testSessionEvent = events.find(event => event.type === 'test_session_end')
Expand All @@ -90,8 +81,10 @@ versions.forEach((version) => {

const stepEvents = events.filter(event => event.type === 'span')

assert.equal(testSessionEvent.content.meta[TEST_SESSION_NAME], 'my-test-session')
assert.include(testSessionEvent.content.resource, 'test_session.playwright test')
assert.equal(testSessionEvent.content.meta[TEST_STATUS], 'fail')
assert.equal(testModuleEvent.content.meta[TEST_SESSION_NAME], 'my-test-session')
assert.include(testModuleEvent.content.resource, 'test_module.playwright test')
assert.equal(testModuleEvent.content.meta[TEST_STATUS], 'fail')
assert.equal(testSessionEvent.content.meta[TEST_TYPE], 'browser')
Expand All @@ -113,6 +106,7 @@ versions.forEach((version) => {
])

testSuiteEvents.forEach(testSuiteEvent => {
assert.equal(testSuiteEvent.content.meta[TEST_SESSION_NAME], 'my-test-session')
if (testSuiteEvent.content.meta[TEST_STATUS] === 'fail') {
assert.exists(testSuiteEvent.content.meta[ERROR_MESSAGE])
}
Expand All @@ -134,6 +128,7 @@ versions.forEach((version) => {
])

testEvents.forEach(testEvent => {
assert.equal(testEvent.content.meta[TEST_SESSION_NAME], 'my-test-session')
assert.exists(testEvent.content.metrics[TEST_SOURCE_START])
assert.equal(
testEvent.content.meta[TEST_SOURCE_FILE].startsWith('ci-visibility/playwright-tests/'), true
Expand Down
15 changes: 5 additions & 10 deletions integration-tests/vitest/vitest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ const {
TEST_CODE_OWNERS,
TEST_CODE_COVERAGE_LINES_PCT,
TEST_SESSION_NAME,
TEST_COMMAND,
TEST_LEVEL_EVENT_TYPES
TEST_COMMAND
} = require('../../packages/dd-trace/src/plugins/util/test')

const versions = ['1.6.0', 'latest']
Expand Down Expand Up @@ -53,23 +52,17 @@ versions.forEach((version) => {

it('can run and report tests', (done) => {
receiver.gatherPayloadsMaxTimeout(({ url }) => url === '/api/v2/citestcycle', payloads => {
const metadataDicts = payloads.flatMap(({ payload }) => payload.metadata)

metadataDicts.forEach(metadata => {
for (const testLevel of TEST_LEVEL_EVENT_TYPES) {
assert.equal(metadata[testLevel][TEST_SESSION_NAME], 'my-test-session')
}
})

const events = payloads.flatMap(({ payload }) => payload.events)

const testSessionEvent = events.find(event => event.type === 'test_session_end')
const testModuleEvent = events.find(event => event.type === 'test_module_end')
const testSuiteEvents = events.filter(event => event.type === 'test_suite_end')
const testEvents = events.filter(event => event.type === 'test')

assert.equal(testSessionEvent.content.meta[TEST_SESSION_NAME], 'my-test-session')
assert.include(testSessionEvent.content.resource, 'test_session.vitest run')
assert.equal(testSessionEvent.content.meta[TEST_STATUS], 'fail')
assert.equal(testModuleEvent.content.meta[TEST_SESSION_NAME], 'my-test-session')
assert.include(testModuleEvent.content.resource, 'test_module.vitest run')
assert.equal(testModuleEvent.content.meta[TEST_STATUS], 'fail')
assert.equal(testSessionEvent.content.meta[TEST_TYPE], 'test')
Expand Down Expand Up @@ -142,10 +135,12 @@ versions.forEach((version) => {
)

testEvents.forEach(test => {
assert.equal(test.content.meta[TEST_SESSION_NAME], 'my-test-session')
assert.equal(test.content.meta[TEST_COMMAND], 'vitest run')
})

testSuiteEvents.forEach(testSuite => {
assert.equal(testSuite.content.meta[TEST_SESSION_NAME], 'my-test-session')
assert.equal(testSuite.content.meta[TEST_COMMAND], 'vitest run')
})
// TODO: check error messages
Expand Down
Loading

0 comments on commit 3082f59

Please sign in to comment.