Skip to content

Commit

Permalink
[ci-visibility] Early flake detection for jest (#3956)
Browse files Browse the repository at this point in the history
  • Loading branch information
juan-fernandez authored and tlhunter committed Feb 14, 2024
1 parent 6f64630 commit 9db687b
Show file tree
Hide file tree
Showing 12 changed files with 574 additions and 101 deletions.
51 changes: 44 additions & 7 deletions integration-tests/ci-visibility-intake.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ const codec = msgpack.createCodec({ int64: true })
const http = require('http')
const multer = require('multer')
const upload = multer()
const zlib = require('zlib')

const { FakeAgent } = require('./helpers')

const DEFAULT_SETTINGS = {
code_coverage: true,
tests_skipping: true,
itr_enabled: true
itr_enabled: true,
early_flake_detection: {
enabled: false,
slow_test_retries: {
'5s': 3
}
}
}

const DEFAULT_SUITES_TO_SKIP = []
Expand All @@ -20,14 +27,20 @@ const DEFAULT_INFO_RESPONSE = {
endpoints: ['/evp_proxy/v2']
}
const DEFAULT_CORRELATION_ID = '1234'
const DEFAULT_KNOWN_TESTS = ['test-suite1.js.test-name1', 'test-suite2.js.test-name2']

let settings = DEFAULT_SETTINGS
let suitesToSkip = DEFAULT_SUITES_TO_SKIP
let gitUploadStatus = DEFAULT_GIT_UPLOAD_STATUS
let infoResponse = DEFAULT_INFO_RESPONSE
let correlationId = DEFAULT_CORRELATION_ID
let knownTests = DEFAULT_KNOWN_TESTS

class FakeCiVisIntake extends FakeAgent {
setKnownTests (newKnownTestsResponse) {
knownTests = newKnownTestsResponse
}

setInfoResponse (newInfoResponse) {
infoResponse = newInfoResponse
}
Expand Down Expand Up @@ -70,7 +83,7 @@ class FakeCiVisIntake extends FakeAgent {
})
})

app.post(['/api/v2/citestcycle', '/evp_proxy/v2/api/v2/citestcycle'], (req, res) => {
app.post(['/api/v2/citestcycle', '/evp_proxy/:version/api/v2/citestcycle'], (req, res) => {
res.status(200).send('OK')
this.emit('message', {
headers: req.headers,
Expand All @@ -81,7 +94,7 @@ class FakeCiVisIntake extends FakeAgent {

app.post([
'/api/v2/git/repository/search_commits',
'/evp_proxy/v2/api/v2/git/repository/search_commits'
'/evp_proxy/:version/api/v2/git/repository/search_commits'
], (req, res) => {
res.status(gitUploadStatus).send(JSON.stringify({ data: [] }))
this.emit('message', {
Expand All @@ -93,7 +106,7 @@ class FakeCiVisIntake extends FakeAgent {

app.post([
'/api/v2/git/repository/packfile',
'/evp_proxy/v2/api/v2/git/repository/packfile'
'/evp_proxy/:version/api/v2/git/repository/packfile'
], (req, res) => {
res.status(202).send('')
this.emit('message', {
Expand All @@ -104,7 +117,7 @@ class FakeCiVisIntake extends FakeAgent {

app.post([
'/api/v2/citestcov',
'/evp_proxy/v2/api/v2/citestcov'
'/evp_proxy/:version/api/v2/citestcov'
], upload.any(), (req, res) => {
res.status(200).send('OK')

Expand All @@ -128,7 +141,7 @@ class FakeCiVisIntake extends FakeAgent {

app.post([
'/api/v2/libraries/tests/services/setting',
'/evp_proxy/v2/api/v2/libraries/tests/services/setting'
'/evp_proxy/:version/api/v2/libraries/tests/services/setting'
], (req, res) => {
res.status(200).send(JSON.stringify({
data: {
Expand All @@ -143,7 +156,7 @@ class FakeCiVisIntake extends FakeAgent {

app.post([
'/api/v2/ci/tests/skippable',
'/evp_proxy/v2/api/v2/ci/tests/skippable'
'/evp_proxy/:version/api/v2/ci/tests/skippable'
], (req, res) => {
res.status(200).send(JSON.stringify({
data: suitesToSkip,
Expand All @@ -157,6 +170,30 @@ class FakeCiVisIntake extends FakeAgent {
})
})

app.post([
'/api/v2/ci/libraries/tests',
'/evp_proxy/:version/api/v2/ci/libraries/tests'
], (req, res) => {
// The endpoint returns compressed data if 'accept-encoding' is set to 'gzip'
const isGzip = req.headers['accept-encoding'] === 'gzip'
const data = JSON.stringify({
data: {
attributes: {
test_full_names: knownTests
}
}
})
res.setHeader('content-type', 'application/json')
if (isGzip) {
res.setHeader('content-encoding', 'gzip')
}
res.status(200).send(isGzip ? zlib.gzipSync(data) : data)
this.emit('message', {
headers: req.headers,
url: req.url
})
})

return new Promise((resolve, reject) => {
const timeoutObj = setTimeout(() => {
reject(new Error('Intake timed out starting up'))
Expand Down
Loading

0 comments on commit 9db687b

Please sign in to comment.