Skip to content

Commit 8ec0cfe

Browse files
[ci-visibility] Early flake detection for jest (DataDog#3956)
1 parent a589b3a commit 8ec0cfe

File tree

12 files changed

+574
-101
lines changed

12 files changed

+574
-101
lines changed

integration-tests/ci-visibility-intake.js

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@ const codec = msgpack.createCodec({ int64: true })
55
const http = require('http')
66
const multer = require('multer')
77
const upload = multer()
8+
const zlib = require('zlib')
89

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

1112
const DEFAULT_SETTINGS = {
1213
code_coverage: true,
1314
tests_skipping: true,
14-
itr_enabled: true
15+
itr_enabled: true,
16+
early_flake_detection: {
17+
enabled: false,
18+
slow_test_retries: {
19+
'5s': 3
20+
}
21+
}
1522
}
1623

1724
const DEFAULT_SUITES_TO_SKIP = []
@@ -20,14 +27,20 @@ const DEFAULT_INFO_RESPONSE = {
2027
endpoints: ['/evp_proxy/v2']
2128
}
2229
const DEFAULT_CORRELATION_ID = '1234'
30+
const DEFAULT_KNOWN_TESTS = ['test-suite1.js.test-name1', 'test-suite2.js.test-name2']
2331

2432
let settings = DEFAULT_SETTINGS
2533
let suitesToSkip = DEFAULT_SUITES_TO_SKIP
2634
let gitUploadStatus = DEFAULT_GIT_UPLOAD_STATUS
2735
let infoResponse = DEFAULT_INFO_RESPONSE
2836
let correlationId = DEFAULT_CORRELATION_ID
37+
let knownTests = DEFAULT_KNOWN_TESTS
2938

3039
class FakeCiVisIntake extends FakeAgent {
40+
setKnownTests (newKnownTestsResponse) {
41+
knownTests = newKnownTestsResponse
42+
}
43+
3144
setInfoResponse (newInfoResponse) {
3245
infoResponse = newInfoResponse
3346
}
@@ -70,7 +83,7 @@ class FakeCiVisIntake extends FakeAgent {
7083
})
7184
})
7285

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

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

94107
app.post([
95108
'/api/v2/git/repository/packfile',
96-
'/evp_proxy/v2/api/v2/git/repository/packfile'
109+
'/evp_proxy/:version/api/v2/git/repository/packfile'
97110
], (req, res) => {
98111
res.status(202).send('')
99112
this.emit('message', {
@@ -104,7 +117,7 @@ class FakeCiVisIntake extends FakeAgent {
104117

105118
app.post([
106119
'/api/v2/citestcov',
107-
'/evp_proxy/v2/api/v2/citestcov'
120+
'/evp_proxy/:version/api/v2/citestcov'
108121
], upload.any(), (req, res) => {
109122
res.status(200).send('OK')
110123

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

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

144157
app.post([
145158
'/api/v2/ci/tests/skippable',
146-
'/evp_proxy/v2/api/v2/ci/tests/skippable'
159+
'/evp_proxy/:version/api/v2/ci/tests/skippable'
147160
], (req, res) => {
148161
res.status(200).send(JSON.stringify({
149162
data: suitesToSkip,
@@ -157,6 +170,30 @@ class FakeCiVisIntake extends FakeAgent {
157170
})
158171
})
159172

173+
app.post([
174+
'/api/v2/ci/libraries/tests',
175+
'/evp_proxy/:version/api/v2/ci/libraries/tests'
176+
], (req, res) => {
177+
// The endpoint returns compressed data if 'accept-encoding' is set to 'gzip'
178+
const isGzip = req.headers['accept-encoding'] === 'gzip'
179+
const data = JSON.stringify({
180+
data: {
181+
attributes: {
182+
test_full_names: knownTests
183+
}
184+
}
185+
})
186+
res.setHeader('content-type', 'application/json')
187+
if (isGzip) {
188+
res.setHeader('content-encoding', 'gzip')
189+
}
190+
res.status(200).send(isGzip ? zlib.gzipSync(data) : data)
191+
this.emit('message', {
192+
headers: req.headers,
193+
url: req.url
194+
})
195+
})
196+
160197
return new Promise((resolve, reject) => {
161198
const timeoutObj = setTimeout(() => {
162199
reject(new Error('Intake timed out starting up'))

0 commit comments

Comments
 (0)