Skip to content

Commit

Permalink
set-output name=retried
Browse files Browse the repository at this point in the history
  • Loading branch information
saturninoabril authored and mikepenz committed Nov 28, 2024
1 parent 0bec6a4 commit eb88944
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
64 changes: 64 additions & 0 deletions __tests__/testParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,69 @@ describe('parseTestReports', () => {
])
})

it('should parse retried tests', async () => {
const {checkName, summary, totalCount, skipped, failed, passed, retried, globalAnnotations} = await parseTestReports(
'checkName',
'summary',
'test_results/junit-server-test/report.xml',
'*',
true,
true,
[],
'{{SUITE_NAME}}/{{TEST_NAME}}',
'/'
)

expect(checkName).toBe('checkName')
expect(summary).toBe('summary')
expect(totalCount).toBe(3)
expect(skipped).toBe(1)
expect(failed).toBe(0)
expect(passed).toBe(2)
expect(retried).toBe(1)
expect(globalAnnotations).toStrictEqual([
{
path: 'com/example/example/server/v8/channels/api4',
start_line: 1,
end_line: 1,
start_column: 0,
end_column: 0,
retries: 1,
annotation_level: 'notice',
status: 'success',
title: 'github.com/example/example/server/v8/channels/api4/TestWebSocketReconnectRace',
message: 'TestWebSocketReconnectRace',
raw_details: ''
},
{
annotation_level: 'notice',
end_column: 0,
end_line: 1,
message: 'TestCreateChannelBookmark',
path: 'com/example/example/server/v8/channels/api4',
raw_details: '',
retries: 0,
start_column: 0,
start_line: 1,
status: 'skipped',
title: 'github.com/example/example/server/v8/channels/api4/TestCreateChannelBookmark',
},
{
annotation_level: 'notice',
end_column: 0,
end_line: 1,
message: 'TestWebSocketUpgrade',
path: 'com/example/example/server/v8/channels/api4',
raw_details: '',
retries: 0,
start_column: 0,
start_line: 1,
status: 'success',
title: 'github.com/example/example/server/v8/channels/api4/TestWebSocketUpgrade',
}
])
})

it('parse corrupt test output', async () => {
const result = await parseTestReports(
'',
Expand Down Expand Up @@ -1296,6 +1359,7 @@ describe('parseTestReports', () => {
foundFiles: 1,
globalAnnotations: [],
passed: 0,
retried: 0,
testResults: []
})
})
Expand Down
3 changes: 3 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export async function run(): Promise<void> {
skipped: 0,
failed: 0,
passed: 0,
retried: 0,
foundFiles: 0,
globalAnnotations: [],
testResults: []
Expand Down Expand Up @@ -96,13 +97,15 @@ export async function run(): Promise<void> {
mergedResult.skipped += testResult.skipped
mergedResult.failed += testResult.failed
mergedResult.passed += testResult.passed
mergedResult.retried += testResult.retried
testResults.push(testResult)
}

core.setOutput('total', mergedResult.totalCount)
core.setOutput('passed', mergedResult.passed)
core.setOutput('skipped', mergedResult.skipped)
core.setOutput('failed', mergedResult.failed)
core.setOutput('retried', mergedResult.retried)

if (!(mergedResult.totalCount > 0 || mergedResult.skipped > 0) && requireTests) {
core.setFailed(`❌ No test results found for ${checkName}`)
Expand Down
15 changes: 15 additions & 0 deletions src/testParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface ActualTestResult {
name: string
totalCount: number
skippedCount: number
retriedCount: number
annotations: Annotation[]
globalAnnotations: Annotation[]
testResults: ActualTestResult[]
Expand All @@ -17,6 +18,7 @@ export interface ActualTestResult {
interface TestCasesResult {
totalCount: number
skippedCount: number
retriedCount: number
annotations: Annotation[]
}

Expand All @@ -27,6 +29,7 @@ export interface TestResult {
skipped: number
failed: number
passed: number
retried: number
foundFiles: number
globalAnnotations: Annotation[]
testResults: ActualTestResult[]
Expand Down Expand Up @@ -271,6 +274,7 @@ async function parseSuite(

let totalCount = 0
let skippedCount = 0
let retriedCount = 0
const annotations: Annotation[] = []

// parse testCases
Expand Down Expand Up @@ -300,6 +304,7 @@ async function parseSuite(
// expand global annotations array
totalCount += parsedTestCases.totalCount
skippedCount += parsedTestCases.skippedCount
retriedCount += parsedTestCases.retriedCount
annotations.push(...parsedTestCases.annotations)
globalAnnotations.push(...parsedTestCases.annotations)
}
Expand All @@ -309,6 +314,7 @@ async function parseSuite(
name: suiteName,
totalCount,
skippedCount,
retriedCount,
annotations,
globalAnnotations,
testResults: []
Expand Down Expand Up @@ -357,6 +363,7 @@ async function parseSuite(
name: suiteName,
totalCount,
skippedCount,
retriedCount,
annotations,
globalAnnotations,
testResults: childSuiteResults
Expand All @@ -368,6 +375,7 @@ async function parseSuite(
name: suiteName,
totalCount,
skippedCount,
retriedCount,
annotations,
globalAnnotations,
testResults: childSuiteResults
Expand All @@ -394,6 +402,7 @@ async function parseTestCases(
const annotations: Annotation[] = []
let totalCount = 0
let skippedCount = 0
let retriedCount = 0
if (checkRetries) {
// identify duplicates, in case of flaky tests, and remove them
const testcaseMap = new Map<string, any>()
Expand All @@ -407,11 +416,14 @@ async function parseTestCases(
if (failed && !previousFailed) {
// previous is a success, drop failure
previous.retries = (previous.retries || 0) + 1
retriedCount += 1
core.debug(`Drop flaky test failure for (1): ${key}`)
} else if (!failed && previousFailed) {
// previous failed, new one not, replace
testcase.retries = (previous.retries || 0) + 1
testcaseMap.set(key, testcase)
retriedCount += 1
core.debug(`Drop flaky test failure for (2): ${JSON.stringify(testcase)}`)
core.debug(`Drop flaky test failure for (2): ${key}`)
}
} else {
Expand Down Expand Up @@ -551,6 +563,7 @@ async function parseTestCases(
return {
totalCount,
skippedCount,
retriedCount,
annotations
}
}
Expand Down Expand Up @@ -623,6 +636,7 @@ export async function parseTestReports(
// get the count of passed and failed tests.
const failed = globalAnnotations.filter(a => a.annotation_level === 'failure').length
const passed = totalCount - failed - skipped
const retried = globalAnnotations.filter(a => a.retries > 0).length

return {
checkName,
Expand All @@ -631,6 +645,7 @@ export async function parseTestReports(
skipped,
failed,
passed,
retried,
foundFiles,
globalAnnotations,
testResults
Expand Down
16 changes: 16 additions & 0 deletions test_results/junit-server-test/report.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="3" failures="1" errors="0" time="24.733407">
<testsuite tests="3" failures="1" time="10.715000" name="github.com/example/example/server/v8/channels/api4" timestamp="2024-10-24T12:07:54Z">
<properties>
<property name="go.version" value="go1.22.6 linux/amd64"></property>
</properties>
<testcase classname="github.com/example/example/server/v8/channels/api4" name="TestWebSocketReconnectRace" time="3.320000">
<failure message="Failed" type="">=== RUN TestWebSocketReconnectRace --- FAIL: TestWebSocketReconnectRace (3.32s)</failure>
</testcase>
<testcase classname="github.com/example/example/server/v8/channels/api4" name="TestCreateChannelBookmark" time="0.000000">
<skipped message="=== RUN TestCreateChannelBookmark --- SKIP: TestCreateChannelBookmark (0.00s)"></skipped>
</testcase>
<testcase classname="github.com/example/example/server/v8/channels/api4" name="TestWebSocketUpgrade" time="2.170000"></testcase>
<testcase classname="github.com/example/example/server/v8/channels/api4" name="TestWebSocketReconnectRace" time="7.780000"></testcase>
</testsuite>
</testsuites>

0 comments on commit eb88944

Please sign in to comment.