Skip to content

Commit 7da9e23

Browse files
authored
[ci] Optimize 'APK's .NET' test job overhead. (#7904)
Optimize overhead for `APK's .NET` CI job: * Use new `start-stop-emulator.yaml` template to start the emulator before the tests begin. If the emulator isn't working, then each test step tries to run, waits 10 minutes, and [then errors out][0]: > **PowerShell exited with code '1'.** > Package Tests · macOS > Tests > APKs .NET · run Mono.Android.NET_Tests-Release Instead, let's just error out completely at the beginning if the emulator isn't available. * Bump the emulator timeout to 15 minutes (from 10 minutes). Using public Mac bots can be slow, maybe giving them a little extra time will result in more successful builds. * Call `Xamarin.Android.sln -t:PrepareJavaInterop` with `--no-restore` to prevent it from running restore on the entire solution. * Don't waste time installing unneeded dependencies: * Legacy dotnet * Mono * NUnit.Console * Extra Android SDK platforms [0]: https://user-images.githubusercontent.com/179295/226654253-2d73b593-f7cd-4a1f-bf50-6a105c63283b.png
1 parent 6e9c3d7 commit 7da9e23

File tree

5 files changed

+22
-21
lines changed

5 files changed

+22
-21
lines changed

build-tools/automation/azure-pipelines.yaml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ variables:
5757
value: '& TestCategory != DotNetIgnore & TestCategory != HybridAOT & TestCategory != MkBundle & TestCategory != MonoSymbolicate & TestCategory != PackagesConfig & TestCategory != StaticProject & TestCategory != SystemApplication'
5858
- name: ExcludedNUnitCategories
5959
value: '& cat != DotNetIgnore & cat != HybridAOT & cat != MkBundle & cat != MonoSymbolicate & cat != PackagesConfig & cat != StaticProject & cat != SystemApplication'
60+
- name: DefaultTestSdkPlatforms # Comma-separated SDK Platform(s) to install on test agents (no spaces)
61+
value: 33
6062
- ${{ if eq(variables['Build.DefinitionName'], 'Xamarin.Android-Private') }}:
6163
- group: AzureDevOps-Artifact-Feeds-Pats
6264
- group: DotNet-MSRC-Storage
@@ -312,11 +314,14 @@ stages:
312314
parameters:
313315
provisionClassic: false
314316
provisionatorChannel: ${{ parameters.provisionatorChannel }}
317+
installLegacyDotNet: false
318+
restoreNUnitConsole: false
319+
updateMono: false
315320

316321
- template: yaml-templates/run-xaprepare.yaml
317322
parameters:
318323
displayName: install emulator
319-
arguments: --s=EmulatorTestDependencies
324+
arguments: --s=EmulatorTestDependencies --android-sdk-platforms="$(DefaultTestSdkPlatforms)"
320325

321326
- task: DownloadPipelineArtifact@2
322327
inputs:
@@ -334,17 +339,19 @@ stages:
334339
parameters:
335340
project: Xamarin.Android.sln
336341
arguments: >-
337-
-t:PrepareJavaInterop -c Debug -m:1 -v:n
342+
-t:PrepareJavaInterop -c Debug --no-restore
338343
-p:DotNetPreviewTool=$(System.DefaultWorkingDirectory)/bin/$(XA.Build.Configuration)/dotnet/dotnet
339344
displayName: prepare java.interop Debug
340345
continueOnError: false
341346

342347
- template: yaml-templates/run-dotnet-preview.yaml
343348
parameters:
344349
project: Xamarin.Android.sln
345-
arguments: -t:PrepareJavaInterop -c $(XA.Build.Configuration) -m:1 -v:n
350+
arguments: -t:PrepareJavaInterop -c $(XA.Build.Configuration) --no-restore
346351
displayName: prepare java.interop $(XA.Build.Configuration)
347352
continueOnError: false
353+
354+
- template: yaml-templates/start-stop-emulator.yaml
348355

349356
- template: yaml-templates/apk-instrumentation.yaml
350357
parameters:
@@ -411,15 +418,9 @@ stages:
411418
testAssembly: $(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/$(DotNetStableTargetFramework)/Xamarin.Android.Tools.Aidl-Tests.dll
412419
testResultsFile: TestResult-Aidl-Tests-macOS-$(XA.Build.Configuration).xml
413420

414-
- task: MSBuild@1
415-
displayName: shut down emulator
416-
inputs:
417-
solution: tests/Mono.Android-Tests/Mono.Android-Tests.csproj
418-
configuration: $(XA.Build.Configuration)
419-
msbuildArguments: >-
420-
/t:AcquireAndroidTarget,ReleaseAndroidTarget
421-
/bl:$(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/shutdown-emulator.binlog
422-
condition: always()
421+
- template: yaml-templates/start-stop-emulator.yaml
422+
parameters:
423+
command: stop
423424

424425
- template: yaml-templates/upload-results.yaml
425426
parameters:

build-tools/automation/yaml-templates/apk-instrumentation.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ steps:
4444
- script: >
4545
DEST="$(Build.StagingDirectory)/Test${{ parameters.configuration }}/${{ parameters.artifactFolder }}/" &&
4646
mkdir -p "$DEST" &&
47-
cp "${{ parameters.artifactSource }}" "$DEST"
47+
cp "${{ parameters.artifactSource }}" "$DEST" ||
48+
echo "copy apk/aab failed" # We don't need to report the error
4849
displayName: copy apk/aab
4950
condition: ne(variables['Agent.JobStatus'], 'Succeeded')
5051
continueOnError: true

build-tools/automation/yaml-templates/setup-test-environment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ parameters:
1212
installLegacyDotNet: true
1313
restoreNUnitConsole: true
1414
updateMono: true
15-
androidSdkPlatforms: 33
15+
androidSdkPlatforms: $(DefaultTestSdkPlatforms)
1616

1717
steps:
1818
- checkout: self

build-tools/automation/yaml-templates/stage-msbuild-emulator-tests.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ stages:
2121
cancelTimeoutInMinutes: 5
2222
workspace:
2323
clean: all
24-
variables:
25-
androidSdkPlatforms: 33
2624
steps:
2725
- template: setup-test-environment.yaml
2826
parameters:
@@ -38,7 +36,7 @@ stages:
3836
- template: run-xaprepare.yaml
3937
parameters:
4038
displayName: install emulator
41-
arguments: --s=EmulatorTestDependencies --android-sdk-platforms="$(androidSdkPlatforms)"
39+
arguments: --s=EmulatorTestDependencies --android-sdk-platforms="$(DefaultTestSdkPlatforms)"
4240

4341
- task: DownloadPipelineArtifact@2
4442
inputs:

build-tools/automation/yaml-templates/start-stop-emulator.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ parameters:
55
avdApiLevel: # Device API level, like '30', required if 'specificImage' is 'true'
66
avdAbi: # Device ABI, like 'x86', required if 'specificImage' is 'true'
77
avdType: # Device AVD, like 'android-wear', required if 'specificImage' is 'true'
8+
launchTimeoutMin: 15 # Minutes to wait for the emulator to start
89

910
steps:
1011
- ${{ if eq(parameters.command, 'start') }}:
@@ -14,9 +15,9 @@ steps:
1415
inputs:
1516
projects: src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Emulator.csproj
1617
${{ if eq(parameters.specificImage, true) }}:
17-
arguments: -c $(XA.Build.Configuration) -t:"InstallAvdImage;AcquireAndroidTarget" -p:TestDeviceName=${{ parameters.deviceName }} -p:TestAvdApiLevel=${{ parameters.avdApiLevel }} -p:TestAvdAbi=${{ parameters.avdAbi }} -p:TestAvdType=${{ parameters.avdType }} -bl:$(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/install-emulator-${{ parameters.avdApiLevel }}.binlog
18+
arguments: -c $(XA.Build.Configuration) -t:"InstallAvdImage;AcquireAndroidTarget" -p:TestDeviceName=${{ parameters.deviceName }} -p:TestAvdApiLevel=${{ parameters.avdApiLevel }} -p:TestAvdAbi=${{ parameters.avdAbi }} -p:TestAvdType=${{ parameters.avdType }} -p:AvdLaunchTimeoutMinutes=${{ parameters.launchTimeoutMin }} -bl:$(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/install-emulator-${{ parameters.avdApiLevel }}.binlog
1819
${{ else }}:
19-
arguments: -c $(XA.Build.Configuration) -t:AcquireAndroidTarget -bl:$(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/start-emulator.binlog
20+
arguments: -c $(XA.Build.Configuration) -t:AcquireAndroidTarget -p:AvdLaunchTimeoutMinutes=${{ parameters.launchTimeoutMin }} -bl:$(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/start-emulator.binlog
2021

2122
- ${{ if eq(parameters.command, 'stop') }}:
2223
- task: DotNetCoreCLI@2
@@ -26,6 +27,6 @@ steps:
2627
inputs:
2728
projects: src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Emulator.csproj
2829
${{ if eq(parameters.specificImage, true) }}:
29-
arguments: -c $(XA.Build.Configuration) -t:"AcquireAndroidTarget,ReleaseAndroidTarget" -p:TestDeviceName=${{ parameters.deviceName }} -p:TestAvdApiLevel=${{ parameters.avdApiLevel }} -p:TestAvdAbi=${{ parameters.avdAbi }} -p:TestAvdType=${{ parameters.avdType }} -bl:$(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/shutdown-emulator.binlog
30+
arguments: -c $(XA.Build.Configuration) -t:"AcquireAndroidTarget,ReleaseAndroidTarget" -p:TestDeviceName=${{ parameters.deviceName }} -p:TestAvdApiLevel=${{ parameters.avdApiLevel }} -p:TestAvdAbi=${{ parameters.avdAbi }} -p:TestAvdType=${{ parameters.avdType }} -p:AvdLaunchTimeoutMinutes=${{ parameters.launchTimeoutMin }} -bl:$(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/shutdown-emulator.binlog
3031
${{ else }}:
31-
arguments: -c $(XA.Build.Configuration) -t:"AcquireAndroidTarget,ReleaseAndroidTarget" -bl:$(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/shutdown-emulator.binlog
32+
arguments: -c $(XA.Build.Configuration) -t:"AcquireAndroidTarget,ReleaseAndroidTarget" -p:AvdLaunchTimeoutMinutes=${{ parameters.launchTimeoutMin }} -bl:$(System.DefaultWorkingDirectory)/bin/Test$(XA.Build.Configuration)/shutdown-emulator.binlog

0 commit comments

Comments
 (0)