-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(apptesting): add --results-file option and improve test verdict reporting #10827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
lfkellogg
wants to merge
2
commits into
main
Choose a base branch
from
feat-apptesting-results-file-logging
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,56 +120,181 @@ export class Distribution { | |
| } | ||
| } | ||
|
|
||
| export interface DeviceExecutionResult { | ||
| device: string; | ||
| state: string; | ||
| failedReason?: string; | ||
| inconclusiveReason?: string; | ||
| actionsJsonGcsUri?: string; | ||
| } | ||
|
|
||
| export interface TestCaseResult { | ||
| displayName: string; | ||
| releaseTestName?: string; | ||
| passed: boolean; | ||
| deviceExecutions: DeviceExecutionResult[]; | ||
| } | ||
|
|
||
| export interface TestResultSummary { | ||
| passed: boolean; | ||
| totalTestCases: number; | ||
| passCount: number; | ||
| failCount: number; | ||
| testCases: TestCaseResult[]; | ||
| } | ||
|
|
||
| /** Wait for release tests to complete */ | ||
| export async function awaitTestResults( | ||
| releaseTests: ReleaseTest[], | ||
| requests: AppDistributionClient, | ||
| ): Promise<void> { | ||
| const releaseTestNames = new Set( | ||
| resultsFilePath?: string, | ||
| ): Promise<TestResultSummary> { | ||
| const pendingReleaseTestNames = new Set( | ||
| releaseTests.map((rt) => rt.name).filter((n): n is string => !!n), | ||
| ); | ||
| const completedReleaseTests = new Map<string, ReleaseTest>(); | ||
|
|
||
| for (let i = 0; i < TEST_MAX_POLLING_RETRIES; i++) { | ||
| utils.logBullet(`${releaseTestNames.size} automated test results are pending...`); | ||
| if (pendingReleaseTestNames.size === 0) { | ||
| break; | ||
| } | ||
| utils.logBullet(`${pendingReleaseTestNames.size} automated test(s) pending completion...`); | ||
| await delay(TEST_POLLING_INTERVAL_MILLIS); | ||
| for (const releaseTestName of releaseTestNames) { | ||
|
|
||
| for (const releaseTestName of Array.from(pendingReleaseTestNames)) { | ||
| const releaseTest = await requests.getReleaseTest(releaseTestName); | ||
| if (releaseTest.deviceExecutions.every((e) => e.state === "PASSED")) { | ||
| releaseTestNames.delete(releaseTestName); | ||
| if (releaseTestNames.size === 0) { | ||
| utils.logSuccess("Automated test(s) passed!"); | ||
| return; | ||
| const isFinished = releaseTest.deviceExecutions.every( | ||
| (e) => e.state && e.state !== "IN_PROGRESS", | ||
| ); | ||
| if (isFinished) { | ||
| pendingReleaseTestNames.delete(releaseTestName); | ||
| completedReleaseTests.set(releaseTestName, releaseTest); | ||
|
|
||
| const displayName = releaseTest.displayName || releaseTestName; | ||
| const allPassed = releaseTest.deviceExecutions.every((e) => e.state === "PASSED"); | ||
| if (allPassed) { | ||
| const deviceList = releaseTest.deviceExecutions | ||
| .map((e) => deviceToString(e.device)) | ||
| .join(", "); | ||
| utils.logSuccess(`✔ Passed: "${displayName}" (${deviceList})`); | ||
| } else { | ||
| continue; | ||
| const failedExecs = releaseTest.deviceExecutions.filter((e) => e.state !== "PASSED"); | ||
| for (const exec of failedExecs) { | ||
| const devStr = deviceToString(exec.device); | ||
| const reason = exec.failedReason || exec.inconclusiveReason || exec.state || "Failed"; | ||
| utils.logWarning(`✖ Failed: "${displayName}" on ${devStr}: ${reason}`); | ||
| const gcsUri = formatActionsGcsUri( | ||
| releaseTest.resultsBucket, | ||
| releaseTest.name, | ||
| exec.device.model, | ||
| ); | ||
| if (gcsUri) { | ||
| logger.info(` Log / Actions detail: ${gcsUri}`); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| for (const execution of releaseTest.deviceExecutions) { | ||
| const device = deviceToString(execution.device); | ||
| switch (execution.state) { | ||
| case "PASSED": | ||
| case "IN_PROGRESS": | ||
| continue; | ||
| case "FAILED": | ||
| throw new FirebaseError( | ||
| `Automated test failed for ${device}: ${execution.failedReason}`, | ||
| { exit: 1 }, | ||
| ); | ||
| case "INCONCLUSIVE": | ||
| throw new FirebaseError( | ||
| `Automated test inconclusive for ${device}: ${execution.inconclusiveReason}`, | ||
| { exit: 1 }, | ||
| ); | ||
| default: | ||
| throw new FirebaseError( | ||
| `Unsupported automated test state for ${device}: ${execution.state}`, | ||
| { exit: 1 }, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| if (pendingReleaseTestNames.size > 0) { | ||
| throw new FirebaseError("It took longer than expected to run your test(s), please try again.", { | ||
| exit: 1, | ||
| }); | ||
| } | ||
|
|
||
| const summaryTestCases: TestCaseResult[] = []; | ||
| let totalFailures = 0; | ||
| let totalPasses = 0; | ||
|
|
||
| for (const rt of releaseTests) { | ||
| const name = rt.name; | ||
| const finalRt = (name && completedReleaseTests.get(name)) || rt; | ||
| const displayName = finalRt.displayName || name || "Test Case"; | ||
| const casePassed = | ||
| finalRt.deviceExecutions.length > 0 && | ||
| finalRt.deviceExecutions.every((e) => e.state === "PASSED"); | ||
|
|
||
| if (casePassed) { | ||
| totalPasses++; | ||
| } else { | ||
| totalFailures++; | ||
| } | ||
|
|
||
| summaryTestCases.push({ | ||
| displayName, | ||
| releaseTestName: name, | ||
| passed: casePassed, | ||
| deviceExecutions: finalRt.deviceExecutions.map((e) => ({ | ||
| device: deviceToString(e.device), | ||
| state: e.state || "UNKNOWN", | ||
| failedReason: e.failedReason, | ||
| inconclusiveReason: e.inconclusiveReason, | ||
| actionsJsonGcsUri: formatActionsGcsUri(finalRt.resultsBucket, name, e.device.model), | ||
| })), | ||
| }); | ||
| } | ||
|
|
||
| const summary: TestResultSummary = { | ||
| passed: totalFailures === 0, | ||
| totalTestCases: summaryTestCases.length, | ||
| passCount: totalPasses, | ||
| failCount: totalFailures, | ||
| testCases: summaryTestCases, | ||
| }; | ||
|
|
||
| if (resultsFilePath) { | ||
| try { | ||
| fs.outputJsonSync(resultsFilePath, summary, { spaces: 2 }); | ||
| utils.logSuccess(`Wrote machine-readable test results to ${resultsFilePath}`); | ||
| } catch (err: unknown) { | ||
| logger.info(`Failed to write results file to ${resultsFilePath}: ${getErrMsg(err)}`); | ||
| } | ||
| } | ||
|
|
||
| if (totalFailures > 0) { | ||
| utils.logWarning( | ||
| `\nAutomated test run finished with failures (${totalFailures} of ${summaryTestCases.length} test cases failed):`, | ||
| ); | ||
| for (const tc of summaryTestCases) { | ||
| if (!tc.passed) { | ||
| utils.logWarning(` - Case "${tc.displayName}":`); | ||
| for (const exec of tc.deviceExecutions) { | ||
| if (exec.state !== "PASSED") { | ||
| const reason = exec.failedReason || exec.inconclusiveReason || exec.state; | ||
| utils.logWarning(` • ${exec.device}: ${reason}`); | ||
| if (exec.actionsJsonGcsUri) { | ||
| utils.logWarning(` GCS actions log: ${exec.actionsJsonGcsUri}`); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| throw new FirebaseError( | ||
| `Automated test(s) failed: ${totalFailures} of ${summaryTestCases.length} test cases failed.`, | ||
| { exit: 1 }, | ||
| ); | ||
| } | ||
|
|
||
| utils.logSuccess( | ||
| `Automated test(s) passed! (${totalPasses} of ${summaryTestCases.length} test cases passed)`, | ||
| ); | ||
| return summary; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add the helper function }
function logTestCaseResult(releaseTest: ReleaseTest, displayName: string): void {
const allPassed =
releaseTest.deviceExecutions.length > 0 &&
releaseTest.deviceExecutions.every((e) => e.state === "PASSED");
if (allPassed) {
const deviceList = releaseTest.deviceExecutions
.map((e) => deviceToString(e.device))
.join(", ");
utils.logSuccess(`✔ Passed: "${displayName}" (${deviceList})`);
return;
}
const failedExecs = releaseTest.deviceExecutions.filter((e) => e.state !== "PASSED");
for (const exec of failedExecs) {
const devStr = deviceToString(exec.device);
const reason = exec.failedReason || exec.inconclusiveReason || exec.state || "Failed";
utils.logWarning(`✖ Failed: "${displayName}" on ${devStr}: ${reason}`);
const gcsUri = formatActionsGcsUri(
releaseTest.resultsBucket,
releaseTest.name,
exec.device.model,
);
if (gcsUri) {
logger.info(` Log / Actions detail: ${gcsUri}`);
}
}
} |
||
|
|
||
| function formatActionsGcsUri( | ||
| resultsBucket: string | undefined, | ||
| releaseTestName: string | undefined, | ||
| model: string, | ||
| ): string | undefined { | ||
| if (!resultsBucket || !releaseTestName) { | ||
| return undefined; | ||
| } | ||
| throw new FirebaseError("It took longer than expected to run your test(s), please try again.", { | ||
| exit: 1, | ||
| }); | ||
| const bucketName = resultsBucket.includes("buckets/") | ||
| ? resultsBucket.split("buckets/")[1] | ||
| : resultsBucket.replace(/^gs:\/\//, ""); | ||
| const testId = releaseTestName.split("/").pop() || ""; | ||
| return `gs://${bucketName}/${testId}/${model}/actions.json`; | ||
| } | ||
|
|
||
| function delay(ms: number): Promise<number> { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To adhere to the repository style guide on reducing nesting and to fix a potential bug with empty
deviceExecutions, we should extract the test case result logging into a helper function and ensure we guard against emptydeviceExecutionsarrays.Currently, if
deviceExecutionsis empty,everyreturnstrue, which would immediately mark the test as finished and passed, logging a success message. However, the final summary on line 214 requiresdeviceExecutions.length > 0to pass, leading to contradictory console output (logging success but exiting with failure).By extracting this logic, we reduce the nesting level from 6 to 4 and ensure consistent handling of empty executions.
References