Skip to content

Commit

Permalink
[ci] Improve test failure artifact uploads (#6681)
Browse files Browse the repository at this point in the history
Fixes .apk/.aab file uploads when an apk test configuration fails.

The filters for log file uploading have also been improved to avoid a
situaton where we attempt to upload a file with the same name twice:

    Copying file '/Users/runner/work/1/s/xamarin-android/bin/TestRelease/logcat-Release-full.log' to '/Users/runner/work/1/a/TestRelease/logcat-Release-full.log' (overwrite destination: False)
    Copying file '/Users/runner/work/1/s/xamarin-android/bin/TestRelease/logcat-ReleaseAab-Mono.Android.NET_Tests.txt' to '/Users/runner/work/1/a/TestRelease/logcat-ReleaseAab-Mono.Android.NET_Tests.txt' (overwrite destination: False)
    ...
    Copying file '/Users/runner/work/1/s/xamarin-android/bin/TestRelease/logcat-Release-full.log' to '/Users/runner/work/1/a/TestRelease/logcat-Release-full.log' (overwrite destination: False)

    Step Xamarin.Android.Prepare.Step_CopyExtraResultFilesForCI failed: The file '/Users/runner/work/1/a/TestRelease/logcat-Release-full.log' already exists.
    System.InvalidOperationException: Step Xamarin.Android.Prepare.Step_CopyExtraResultFilesForCI failed: The file '/Users/runner/work/1/a/TestRelease/logcat-Release-full.log' already exists.
     ---> System.IO.IOException: The file '/Users/runner/work/1/a/TestRelease/logcat-Release-full.log' already exists.

The `logcat-Release-full.log` file matched both `logcat*` and `*log`
upload file filters. Attempts to copy it twice would fail, which caused
us to miss certain files in the test result output that was eventually
uploaded.

MSBuild .binlog files will now be uploaded as test attachments for
failing tests.
  • Loading branch information
pjcollins authored Jan 28, 2022
1 parent f61cd81 commit ce0d212
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ steps:
-bl:$(System.DefaultWorkingDirectory)/bin/Test${{ parameters.configuration }}/run-${{ parameters.testName }}.binlog
-v:n -c ${{ parameters.configuration }} ${{ parameters.extraBuildArgs }}
condition: ${{ parameters.condition }}
continueOnError: true

- script: >
DEST="$(Build.ArtifactStagingDirectory)/${{ parameters.artifactFolder }}/" &&
DEST="$(Build.StagingDirectory)/Test${{ parameters.configuration }}/${{ parameters.artifactFolder }}/" &&
mkdir -p "$DEST" &&
cp "${{ parameters.artifactSource }}" "$DEST"
displayName: copy apk/aab
condition: eq(variables['agent.jobstatus'], 'SucceededWithIssues')
condition: ne(variables['Agent.JobStatus'], 'Succeeded')
continueOnError: true

- task: PublishTestResults@2
Expand Down
5 changes: 2 additions & 3 deletions build-tools/scripts/TestApks.targets
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<AvdLaunchTimeoutMinutes Condition=" '$(AvdLaunchTimeoutMinutes)' == '' ">5</AvdLaunchTimeoutMinutes>
<AvdLaunchTimeoutSeconds>$([MSBuild]::Multiply($(AvdLaunchTimeoutMinutes), 60))</AvdLaunchTimeoutSeconds>
<AvdLaunchTimeoutMS>$([MSBuild]::Multiply($(AvdLaunchTimeoutSeconds), 1000))</AvdLaunchTimeoutMS>
<_LogcatFilename>$(MSBuildThisFileDirectory)..\..\bin\Test$(Configuration)\logcat-$(Configuration)-full.log</_LogcatFilename>
<_LogcatFilenameBase>$(MSBuildThisFileDirectory)..\..\bin\Test$(Configuration)\logcat-$(Configuration)$(TestsFlavor)</_LogcatFilenameBase>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -69,7 +69,7 @@
AvdManagerHome="$(AvdManagerHome)"
Arguments="$(TestEmulatorArguments)"
ImageName="$(TestAvdName)"
LogcatFile="$(_LogcatFilename)"
LogcatFile="$(_LogcatFilenameBase)-full.txt"
Port="$(_AdbEmulatorPort)"
ToolExe="$(EmulatorToolExe)"
ToolPath="$(EmulatorToolPath)">
Expand Down Expand Up @@ -247,7 +247,6 @@
<PropertyGroup>
<_IncludeCategories Condition=" '$(IncludeCategories)' != '' ">include=$(IncludeCategories)</_IncludeCategories>
<_ExcludeCategories Condition=" '$(ExcludeCategories)' != '' ">exclude=$(ExcludeCategories)</_ExcludeCategories>
<_LogcatFilenameBase>$(MSBuildThisFileDirectory)..\..\bin\Test$(Configuration)\logcat-$(Configuration)$(TestsFlavor)</_LogcatFilenameBase>
<PlotDataLabelSuffix Condition=" '$(PlotDataLabelSuffix)' == '' ">$(TestsFlavor)</PlotDataLabelSuffix>
</PropertyGroup>
<RunInstrumentationTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void CopyExtraBuildFiles (string destinationRoot, Context context)
string [] testConfigFiles = {
"*.apkdesc",
"*.aabdesc",
"logcat*",
"logcat-*.txt",
"*log",
"TestOutput-*.txt",
"Timing_*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,9 @@ protected virtual void CleanupTest ()
foreach (var file in Directory.GetFiles (Path.Combine (output), "*.log", SearchOption.AllDirectories)) {
TestContext.AddTestAttachment (file, Path.GetFileName (output));
}
foreach (var bl in Directory.GetFiles (Path.Combine (output), "*.binlog", SearchOption.AllDirectories)) {
TestContext.AddTestAttachment (bl, Path.GetFileName (output));
}
}
}
}
Expand Down

0 comments on commit ce0d212

Please sign in to comment.