Skip to content

Commit 9d77ff1

Browse files
authored
[Tests] Make sure emulator is killed after tests fail (#2167)
We currently fail to kill the emulator if any of the steps executing APK tests fail. This is because the failed task stops execution of all the other targets defined in that file. In effect we leave running instances of the emulator on the build bots, should such a failure happen. This diff adds `ContinueOnError="ErrorAndContinue" to each task in the target file so that we are sure to hit the `ReleaseAndroidTarget` target no matter what.
1 parent 743e69a commit 9d77ff1

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

build-tools/scripts/TestApks.targets

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,22 @@
6161
<Xamarin.Android.Tools.BootstrapTasks.Adb
6262
EnvironmentVariables="ADB_TRACE=all"
6363
Condition=" '$(_ValidAdbTarget)' != 'True' "
64+
ContinueOnError="ErrorAndContinue"
6465
Arguments="$(_EmuTarget) shell 'counter=0; while [ $counter -lt 60 ] &amp;&amp; [ &quot;`getprop sys.boot_completed`&quot; != &quot;1&quot; ]; do echo Waiting for device to fully boot; sleep 1; let &quot;counter++&quot;; done'"
6566
ToolExe="$(AdbToolExe)"
6667
ToolPath="$(AdbToolPath)"
6768
Timeout="120000"
6869
/>
6970
<Xamarin.Android.Tools.BootstrapTasks.Adb
7071
Arguments="$(_AdbTarget) shell setprop debug.mono.log timing"
72+
IgnoreExitCode="True"
7173
ToolExe="$(AdbToolExe)"
7274
ToolPath="$(AdbToolPath)"
7375
Timeout="60000"
7476
/>
7577
<Xamarin.Android.Tools.BootstrapTasks.Adb
7678
Arguments="$(_AdbTarget) logcat -G 4M"
79+
IgnoreExitCode="True"
7780
ToolExe="$(AdbToolExe)"
7881
ToolPath="$(AdbToolPath)"
7982
Timeout="60000"
@@ -87,35 +90,35 @@
8790
<Target Name="ReleaseAndroidTarget">
8891
<Xamarin.Android.Tools.BootstrapTasks.Adb
8992
Condition="'@(_FailedComponent)' != ''"
90-
ContinueOnError="True"
93+
ContinueOnError="ErrorAndContinue"
9194
Arguments="$(_EmuTarget) logcat -d"
9295
ToolExe="$(AdbToolExe)"
9396
ToolPath="$(AdbToolPath)"
9497
Timeout="120000"
9598
/>
9699
<Xamarin.Android.Tools.BootstrapTasks.Adb
97100
Condition=" '$(_EmuTarget)' != '' "
98-
ContinueOnError="True"
101+
ContinueOnError="ErrorAndContinue"
99102
Arguments="$(_EmuTarget) emu kill"
100103
ToolExe="$(AdbToolExe)"
101104
ToolPath="$(AdbToolPath)"
102105
Timeout="60000"
103106
/>
104107
<KillProcess
105108
Condition=" '$(_EmuTarget)' != '' "
106-
ContinueOnError="True"
109+
ContinueOnError="ErrorAndContinue"
107110
ProcessId="$(_EmuPid)"
108111
/>
109112
<Xamarin.Android.Tools.BootstrapTasks.Adb
110113
Arguments="kill-server"
111-
ContinueOnError="True"
114+
ContinueOnError="ErrorAndContinue"
112115
ToolExe="$(AdbToolExe)"
113116
ToolPath="$(AdbToolPath)"
114117
Timeout="60000"
115118
/>
116119
<Exec
117120
Condition=" '$(HostOS)' != 'Windows' And '$(_EmuTarget)' != '' "
118-
ContinueOnError="True"
121+
ContinueOnError="ErrorAndContinue"
119122
Command="kill -HUP $(_EmuPid)"
120123
/>
121124
<Sleep
@@ -124,7 +127,7 @@
124127
/>
125128
<Exec
126129
Condition=" '$(HostOS)' != 'Windows' And '$(_EmuTarget)' != '' "
127-
ContinueOnError="True"
130+
ContinueOnError="ErrorAndContinue"
128131
Command="kill -KILL $(_EmuPid)"
129132
/>
130133
</Target>
@@ -149,6 +152,7 @@
149152
Condition=" '@(TestApk)' != '' ">
150153
<Xamarin.Android.Tools.BootstrapTasks.Adb
151154
Arguments="$(_AdbTarget) $(AdbOptions) install &quot;%(TestApk.Identity)&quot;"
155+
ContinueOnError="ErrorAndContinue"
152156
ToolExe="$(AdbToolExe)"
153157
ToolPath="$(AdbToolPath)"
154158
Timeout="120000"
@@ -170,6 +174,7 @@
170174
Condition=" '@(TestApk)' != '' ">
171175
<Xamarin.Android.Tools.BootstrapTasks.Adb
172176
Condition=" '@(TestApkPermission)' != '' "
177+
ContinueOnError="ErrorAndContinue"
173178
Arguments="$(_AdbTarget) $(AdbOptions) shell pm grant %(TestApkPermission.Package) android.permission.%(TestApkPermission.Identity)"
174179
ToolExe="$(AdbToolExe)"
175180
ToolPath="$(AdbToolPath)"
@@ -182,10 +187,11 @@
182187
</PropertyGroup>
183188
<RunInstrumentationTests
184189
Condition=" '%(TestApkInstrumentation.Identity)' != ''"
190+
ContinueOnError="ErrorAndContinue"
185191
AdbTarget="$(_AdbTarget)"
186192
AdbOptions="$(AdbOptions)"
187193
LogLevel="Verbose"
188-
PackageName="%(TestApkInstrumentation.Package)"
194+
PackageName="%(TestApkInstrumentation.Package)"
189195
Component="%(TestApkInstrumentation.Package)/%(TestApkInstrumentation.Identity)"
190196
NUnit2TestResultsFile="%(TestApkInstrumentation.ResultsPath)"
191197
LogcatFilename="$(_LogcatFilenameBase)-%(TestApkInstrumentation.Package).txt"
@@ -198,6 +204,7 @@
198204
</RunInstrumentationTests>
199205
<RunUITests
200206
Condition=" '%(TestApk.Activity)' != '' "
207+
ContinueOnError="ErrorAndContinue"
201208
AdbTarget="$(_AdbTarget)"
202209
AdbOptions="$(AdbOptions)"
203210
Activity="%(TestApk.Activity)"
@@ -208,6 +215,7 @@
208215
</RunUITests>
209216
<ProcessLogcatTiming
210217
Condition=" '%(TestApk.TimingDefinitionsFilename)' != '' And Exists ('$(_LogcatFilenameBase)-%(TestApk.Package).txt')"
218+
ContinueOnError="ErrorAndContinue"
211219
InputFilename="$(_LogcatFilenameBase)-%(TestApk.Package).txt"
212220
ApplicationPackageName="%(TestApk.Package)"
213221
ResultsFilename="%(TestApk.TimingResultsFilename)"
@@ -260,14 +268,17 @@
260268
<Exec
261269
Condition=" '$(HostOS)' == 'Darwin' And '%(TestApk.ApkSizesDefinitionFilename)' != '' "
262270
Command="stat -f &quot;stat: %z %N&quot; &quot;%(TestApk.Identity)&quot; > &quot;$(OutputPath)%(TestApk.ApkSizesInputFilename)&quot;"
271+
ContinueOnError="ErrorAndContinue"
263272
/>
264273
<Exec
265274
Condition=" '$(HostOS)' == 'Linux' And '%(TestApk.ApkSizesDefinitionFilename)' != '' "
266275
Command="stat -c &quot;stat: %s %N&quot; &quot;%(TestApk.Identity)&quot; > &quot;$(OutputPath)%(TestApk.ApkSizesInputFilename)&quot;"
276+
ContinueOnError="ErrorAndContinue"
267277
/>
268278
<Exec
269279
Condition=" '%(TestApk.ApkSizesDefinitionFilename)' != '' "
270-
Command="unzip -l &quot;%(TestApk.Identity)&quot; >> &quot;$(OutputPath)%(TestApk.ApkSizesInputFilename)&quot;" />
280+
Command="unzip -l &quot;%(TestApk.Identity)&quot; >> &quot;$(OutputPath)%(TestApk.ApkSizesInputFilename)&quot;"
281+
ContinueOnError="ErrorAndContinue" />
271282
<ProcessPlotInput
272283
Condition=" '%(TestApk.ApkSizesDefinitionFilename)' != '' "
273284
InputFilename="$(OutputPath)%(TestApk.ApkSizesInputFilename)"
@@ -276,6 +287,7 @@
276287
DefinitionsFilename="%(TestApk.ApkSizesDefinitionFilename)"
277288
AddResults="True"
278289
LabelSuffix="-$(Configuration)$(TestsAotName)"
290+
ContinueOnError="ErrorAndContinue"
279291
/>
280292
</Target>
281293
</Project>

0 commit comments

Comments
 (0)