Skip to content

Commit 91a3972

Browse files
authored
[tests] Run tests in parallel on non-Windows (#2224)
What do we want? Faster unit test execution! How do we do that? By running things in parallel! Some of our existing tests are already run in parallel, such as the `src/Xamarin.Android.Build.Tasks/Tests` tests which use NUnit's `[Parallelizable(ParallelScope.Children)]`, but there is currently no way to run the `Xamarin.Android.Build.Tasks` NUnit tests *concurrently* with the on-device `.apk` tests concurrently with the Java.Interop unit tests concurrently with... We *think* there might be a "win" here, as the `Xamarin.Android.Build.Tasks` unit tests are heavily I/O bound, while the `.apk` BCL tests are -- presumably -- CPU bound, so executing these at the same time might net some nice time savings. Spike the idea by updating the `RunAllTests` target to *generate a shell script* which executes `msbuild` to run the appropriate test target, in the background, then waiting for all jobs to finish. The generated `bin/Test$(Configuration)/parallel-targets.sh` file resembles: echo Executing in background: msbuild …/build-tools/scripts/RunTests.targets /v:normal /binaryLogger:"…/msbuild-20181012T083249-Target-RunNUnitTests.binlog" /t:RunNUnitTests msbuild …/build-tools/scripts/RunTests.targets /v:normal /binaryLogger:"…/msbuild-20181012T083249-Target-RunNUnitTests.binlog" /t:RunNUnitTests & wait exit 0
1 parent 5e47af3 commit 91a3972

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

build-tools/scripts/RunTests.targets

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,51 @@
138138
<MSBuild Projects="$(MSBuildThisFileDirectory)..\timing\timing.csproj" Targets="MSBuildTiming" />
139139
</Target>
140140
<ItemGroup>
141-
<_RunTestTarget Include="RunNUnitTests" />
142-
<_RunTestTarget Include="RunJavaInteropTests" />
143-
<_RunTestTarget Include="RunApkTests" />
141+
<_RunParallelTestTarget Include="RunNUnitTests" />
142+
<_RunParallelTestTarget Include="RunJavaInteropTests" />
143+
<_RunParallelTestTarget Include="RunApkTests" />
144+
</ItemGroup>
145+
<ItemGroup>
144146
<_RunTestTarget Include="RunPerformanceTests" />
145147
</ItemGroup>
146148
<Target Name="RunAllTests">
147149
<MSBuild
150+
Condition=" '$(HostOS)' == 'Windows' "
148151
ContinueOnError="ErrorAndContinue"
149152
Projects="$(MSBuildThisFileDirectory)RunTests.targets"
150153
RunEachTargetSeparately="True"
151-
Targets="@(_RunTestTarget)"
154+
Targets="@(_RunParallelTestTarget)"
152155
/>
153-
</Target>
156+
<ItemGroup Condition=" '$(USE_MSBUILD)' == '1' ">
157+
<_RunParallelTestTarget>
158+
<_BinLog>$(_XABinLogPrefix)-$([System.DateTime]::Now.ToString ("yyyyMMddTHHmmss"))-Target-%(Identity).binlog"</_BinLog>
159+
</_RunParallelTestTarget>
160+
</ItemGroup>
161+
<ItemGroup>
162+
<_Commands Include="@(_RunParallelTestTarget->'echo Executing in background: msbuild $(MSBuildThisFileDirectory)RunTests.targets %(_BinLog) /t:%(Identity)')" />
163+
<_Commands Include="@(_RunParallelTestTarget->'msbuild $(MSBuildThisFileDirectory)RunTests.targets %(_BinLog) /t:%(Identity) &amp;')" />
164+
<_Commands Include="wait" />
165+
<_Commands Include="exit 0" />
166+
</ItemGroup>
167+
<PropertyGroup>
168+
<_ParallelTargets>$(MSBuildThisFileDirectory)..\..\bin\Test$(Configuration)\parallel-targets.sh</_ParallelTargets>
169+
</PropertyGroup>
170+
<WriteLinesToFile
171+
File="$(_ParallelTargets)"
172+
Lines="@(_Commands)"
173+
Overwrite="True"
174+
/>
175+
<Exec
176+
Condition=" '$(HostOS)' != 'Windows' "
177+
ContinueOnError="ErrorAndContinue"
178+
WorkingDirectory="$(_TopDir)"
179+
Command="bash &quot;$(_ParallelTargets)&quot;"
180+
/>
181+
<MSBuild
182+
ContinueOnError="ErrorAndContinue"
183+
Projects="$(MSBuildThisFileDirectory)RunTests.targets"
184+
RunEachTargetSeparately="True"
185+
Targets="@(_RunTestTarget)"
186+
/>
187+
</Target>
154188
</Project>
155-

0 commit comments

Comments
 (0)