Skip to content

Commit 5f71a33

Browse files
authored
test: use successRate for gateway conformance tests (#83)
* test: use successRate for gateway conformance tests * chore: lint fix * chore: allow overriding success rate via command line * chore: lint fix
1 parent c1a795f commit 5f71a33

File tree

1 file changed

+74
-103
lines changed

1 file changed

+74
-103
lines changed

packages/gateway-conformance/src/conformance.spec.ts

+74-103
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ interface TestConfig {
1515
spec?: string
1616
skip?: string[]
1717
run?: string[]
18-
maxFailures: number
19-
minimumSuccesses?: number
18+
successRate: number
2019
}
2120

2221
function getGatewayConformanceBinaryPath (): string {
@@ -43,224 +42,219 @@ function getConformanceTestArgs (name: string, gwcArgs: string[] = [], goTestArg
4342
]
4443
}
4544

45+
/**
46+
* You can see what the latest success rates are by running the following command:
47+
*
48+
* ```
49+
* cd ../../ && npm run build && cd packages/gateway-conformance && SUCCESS_RATE=100 npm run test -- --bail false
50+
* ```
51+
*/
4652
const tests: TestConfig[] = [
4753
{
4854
name: 'TestMetadata',
4955
run: ['TestMetadata'],
50-
maxFailures: 0,
51-
minimumSuccesses: 1
56+
successRate: 100
5257
},
5358
{
5459
name: 'TestDagPbConversion',
5560
run: ['TestDagPbConversion'],
56-
maxFailures: 51,
57-
minimumSuccesses: 14
61+
successRate: 35.38
5862
},
5963
{
6064
name: 'TestPlainCodec',
6165
run: ['TestPlainCodec'],
62-
maxFailures: 83,
63-
minimumSuccesses: 15
66+
successRate: 39.86
6467
},
6568
{
6669
name: 'TestPathing',
6770
run: ['TestPathing'],
68-
maxFailures: 13,
69-
minimumSuccesses: 0
71+
successRate: 23.53
7072
},
7173
{
7274
name: 'TestDNSLinkGatewayUnixFSDirectoryListing',
7375
run: ['TestDNSLinkGatewayUnixFSDirectoryListing'],
74-
maxFailures: 20,
75-
minimumSuccesses: 0
76+
successRate: 0
7677
},
7778
{
7879
name: 'TestCors',
7980
run: ['TestCors'],
80-
maxFailures: 11,
81-
minimumSuccesses: 0
81+
successRate: 0
8282
},
8383
{
8484
name: 'TestGatewayJsonCbor',
8585
run: ['TestGatewayJsonCbor'],
86-
maxFailures: 9,
87-
minimumSuccesses: 0
86+
successRate: 44.44
8887
},
8988
// currently results in an infinite loop without verified-fetch stopping the request whether sessions are enabled or not.
9089
// {
9190
// name: 'TestNativeDag',
9291
// run: ['TestNativeDag'],
93-
// maxFailures: 2,
94-
// minimumSuccesses: 0
92+
// successRate: 100
9593
// },
9694
{
9795
name: 'TestGatewayJSONCborAndIPNS',
9896
run: ['TestGatewayJSONCborAndIPNS'],
99-
maxFailures: 25,
100-
minimumSuccesses: 8
97+
successRate: 24.24
10198
},
10299
{
103100
name: 'TestGatewayIPNSPath',
104101
run: ['TestGatewayIPNSPath'],
105-
maxFailures: 8,
106-
minimumSuccesses: 3
102+
successRate: 27.27
107103
},
108104
{
109105
name: 'TestRedirectCanonicalIPNS',
110106
run: ['TestRedirectCanonicalIPNS'],
111-
maxFailures: 7,
112-
minimumSuccesses: 0
107+
successRate: 0
113108
},
114109
{
115110
name: 'TestGatewayBlock',
116111
run: ['TestGatewayBlock'],
117-
maxFailures: 25,
118-
minimumSuccesses: 4
112+
successRate: 37.93
119113
},
120114
{
121115
name: 'TestTrustlessRawRanges',
122116
run: ['TestTrustlessRawRanges'],
123-
maxFailures: 5,
124-
minimumSuccesses: 7
117+
successRate: 75
125118
},
126119
{
127120
name: 'TestTrustlessRaw',
128121
run: ['TestTrustlessRaw'],
129-
maxFailures: 29,
130-
minimumSuccesses: 7
122+
successRate: 55.56
131123
},
132124
{
133125
name: 'TestGatewayIPNSRecord',
134126
run: ['TestGatewayIPNSRecord'],
135-
maxFailures: 23,
136-
minimumSuccesses: 0
127+
successRate: 0
137128
},
138129
{
139130
name: 'TestTrustlessCarOrderAndDuplicates',
140131
run: ['TestTrustlessCarOrderAndDuplicates'],
141-
maxFailures: 26,
142-
minimumSuccesses: 3
132+
successRate: 13.79
143133
},
144134
// times out
145135
// {
146136
// name: 'TestTrustlessCarEntityBytes',
147137
// run: ['TestTrustlessCarEntityBytes'],
148-
// maxFailures: 122,
149-
// minimumSuccesses: 55
138+
// successRate: 100
150139
// },
151140
{
152141
name: 'TestTrustlessCarDagScopeAll',
153142
run: ['TestTrustlessCarDagScopeAll'],
154-
maxFailures: 23,
155-
minimumSuccesses: 10
143+
successRate: 36.36
156144
},
157145
{
158146
name: 'TestTrustlessCarDagScopeEntity',
159147
run: ['TestTrustlessCarDagScopeEntity'],
160-
maxFailures: 56,
161-
minimumSuccesses: 25
148+
successRate: 34.57
162149
},
163150
{
164151
name: 'TestTrustlessCarDagScopeBlock',
165152
run: ['TestTrustlessCarDagScopeBlock'],
166-
maxFailures: 34,
167-
minimumSuccesses: 15
153+
successRate: 34.69
168154
},
169155
{
170156
name: 'TestTrustlessCarPathing',
171157
run: ['TestTrustlessCarPathing'],
172-
maxFailures: 45,
173-
minimumSuccesses: 20
158+
successRate: 33.85
174159
},
175160
{
176161
name: 'TestSubdomainGatewayDNSLinkInlining',
177162
run: ['TestSubdomainGatewayDNSLinkInlining'],
178-
maxFailures: 41,
179-
minimumSuccesses: 0
163+
successRate: 0
180164
},
181165
{
182166
name: 'TestGatewaySubdomainAndIPNS',
183167
run: ['TestGatewaySubdomainAndIPNS'],
184-
maxFailures: 95,
185-
minimumSuccesses: 0
168+
successRate: 0
186169
},
187170
{
188171
name: 'TestGatewaySubdomains',
189172
run: ['TestGatewaySubdomains'],
190-
maxFailures: 279,
191-
minimumSuccesses: 0
173+
successRate: 7.17
192174
},
193175
// times out
194176
// {
195177
// name: 'TestUnixFSDirectoryListingOnSubdomainGateway',
196178
// run: ['TestUnixFSDirectoryListingOnSubdomainGateway'],
197-
// maxFailures: 39,
198-
// minimumSuccesses: 0
179+
// successRate: 100
199180
// },
200181
{
201182
name: 'TestRedirectsFileWithIfNoneMatchHeader',
202183
run: ['TestRedirectsFileWithIfNoneMatchHeader'],
203-
maxFailures: 15,
204-
minimumSuccesses: 0
184+
successRate: 0
205185
},
206186
{
207187
name: 'TestRedirectsFileSupportWithDNSLink',
208188
run: ['TestRedirectsFileSupportWithDNSLink'],
209-
maxFailures: 17,
210-
minimumSuccesses: 6
189+
successRate: 26.09
211190
},
212191
{
213192
name: 'TestRedirectsFileSupport',
214193
run: ['TestRedirectsFileSupport'],
215-
maxFailures: 252,
216-
minimumSuccesses: 6
194+
successRate: 2.33
217195
},
218196
{
219197
name: 'TestPathGatewayMiscellaneous',
220198
run: ['TestPathGatewayMiscellaneous'],
221-
maxFailures: 3,
222-
minimumSuccesses: 0
199+
successRate: 100
223200
},
224201
{
225202
name: 'TestGatewayUnixFSFileRanges',
226203
run: ['TestGatewayUnixFSFileRanges'],
227-
maxFailures: 10,
228-
minimumSuccesses: 5
204+
successRate: 40
229205
},
230206
{
231207
name: 'TestGatewaySymlink',
232208
run: ['TestGatewaySymlink'],
233-
maxFailures: 9,
234-
minimumSuccesses: 0
209+
successRate: 33.33
235210
},
236211
{
237212
name: 'TestGatewayCacheWithIPNS',
238213
run: ['TestGatewayCacheWithIPNS'],
239-
maxFailures: 27,
240-
minimumSuccesses: 15
214+
successRate: 35.71
241215
},
242216
// times out
243217
// {
244218
// name: 'TestGatewayCache',
245219
// run: ['TestGatewayCache'],
246-
// maxFailures: 71,
247-
// minimumSuccesses: 23
220+
// successRate: 100
248221
// },
249222
// times out
250223
// {
251224
// name: 'TestUnixFSDirectoryListing',
252225
// run: ['TestUnixFSDirectoryListing'],
253-
// maxFailures: 50,
254-
// minimumSuccesses: 0
226+
// successRate: 100
255227
// },
256228
{
257229
name: 'TestTar',
258230
run: ['TestTar'],
259-
maxFailures: 16,
260-
minimumSuccesses: 8
231+
successRate: 50
261232
}
262233
]
263234

235+
async function getReportDetails (path: string): Promise<{ failureCount: number, successCount: number, successRate: number }> {
236+
let failureCount = 0
237+
let successCount = 0
238+
239+
// parse the newline delimited JSON report at gwc-report-${name}.json and count the number of "PASS:" and "FAIL:" lines
240+
const report = await readFile(path, 'utf8')
241+
const lines = report.split('\n')
242+
for (const line of lines) {
243+
if (line.includes('--- FAIL:')) {
244+
failureCount++
245+
} else if (line.includes('--- PASS:')) {
246+
successCount++
247+
}
248+
}
249+
const successRate = Number.parseFloat(((successCount / (successCount + failureCount)) * 100).toFixed(2))
250+
251+
return {
252+
failureCount,
253+
successCount,
254+
successRate
255+
}
256+
}
257+
264258
describe('@helia/verified-fetch - gateway conformance', function () {
265259
before(async () => {
266260
if (process.env.KUBO_GATEWAY == null) {
@@ -325,10 +319,11 @@ describe('@helia/verified-fetch - gateway conformance', function () {
325319
}
326320
})
327321

328-
tests.forEach(({ name, spec, skip, run, maxFailures, minimumSuccesses }) => {
322+
tests.forEach(({ name, spec, skip, run, successRate: minSuccessRate }) => {
329323
const log = logger.forComponent(name)
324+
const expectedSuccessRate = process.env.SUCCESS_RATE != null ? Number.parseFloat(process.env.SUCCESS_RATE) : minSuccessRate
330325

331-
it(`has no more than ${maxFailures} failing tests for ${name}`, async function () {
326+
it(`${name} has a success rate of at least ${expectedSuccessRate}%`, async function () {
332327
const { stderr, stdout } = await execa(binaryPath, getConformanceTestArgs(name,
333328
[
334329
...(spec != null ? ['--specs', spec] : [])
@@ -342,22 +337,8 @@ describe('@helia/verified-fetch - gateway conformance', function () {
342337
log(stdout)
343338
log.error(stderr)
344339

345-
let failureCount = 0
346-
let successCount = 0
347-
348-
// parse the newline delimited JSON report at gwc-report-${name}.json and count the number of "PASS:" and "FAIL:" lines
349-
const report = await readFile(`gwc-report-${name}.json`, 'utf8')
350-
const lines = report.split('\n')
351-
for (const line of lines) {
352-
if (line.includes('--- FAIL:')) {
353-
failureCount++
354-
} else if (line.includes('--- PASS:')) {
355-
successCount++
356-
}
357-
}
358-
359-
expect(failureCount).to.be.lessThanOrEqual(maxFailures)
360-
expect(successCount).to.be.greaterThanOrEqual(minimumSuccesses ?? 0)
340+
const { successRate } = await getReportDetails(`gwc-report-${name}.json`)
341+
expect(successRate).to.be.greaterThanOrEqual(expectedSuccessRate)
361342
})
362343
})
363344

@@ -382,22 +363,12 @@ describe('@helia/verified-fetch - gateway conformance', function () {
382363

383364
log(stdout)
384365
log.error(stderr)
385-
let failureCount = 0
386-
let successCount = 0
387366

388-
// parse the newline delimited JSON report at gwc-report-${name}.json and count the number of "PASS:" and "FAIL:" lines
389-
const report = await readFile('gwc-report-all.json', 'utf8')
390-
const lines = report.split('\n')
391-
for (const line of lines) {
392-
if (line.includes('--- FAIL:')) {
393-
failureCount++
394-
} else if (line.includes('--- PASS:')) {
395-
successCount++
396-
}
397-
}
398-
// CI has 1134 failures, but I get 1129 locally.
367+
const { failureCount, successCount, successRate } = await getReportDetails('gwc-report-all.json')
368+
399369
expect(failureCount).to.be.lessThanOrEqual(1134)
400370
expect(successCount).to.be.greaterThanOrEqual(262)
371+
expect(successRate).to.be.greaterThanOrEqual(18.77)
401372
})
402373
})
403374
})

0 commit comments

Comments
 (0)