Skip to content

Commit 563fd17

Browse files
committed
[tests] Run tests in parallel on non-Windows
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 319158f commit 563fd17

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

build-tools/scripts/RunTests.targets

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,36 @@
145145
</ItemGroup>
146146
<Target Name="RunAllTests">
147147
<MSBuild
148+
Condition=" '$(HostOS)' == 'Windows' "
148149
ContinueOnError="ErrorAndContinue"
149150
Projects="$(MSBuildThisFileDirectory)RunTests.targets"
150151
RunEachTargetSeparately="True"
151152
Targets="@(_RunTestTarget)"
152153
/>
154+
<ItemGroup Condition=" '$(USE_MSBUILD)' == '1' ">
155+
<_RunTestTarget>
156+
<_BinLog>$(_XABinLogPrefix)-$([System.DateTime]::Now.ToString ("yyyyMMddTHHmmss"))-Target-%(Identity).binlog"</_BinLog>
157+
</_RunTestTarget>
158+
</ItemGroup>
159+
<ItemGroup>
160+
<_Commands Include="@(_RunTestTarget->'echo Executing in background: msbuild $(MSBuildThisFileDirectory)RunTests.targets %(_BinLog) /t:%(Identity)')" />
161+
<_Commands Include="@(_RunTestTarget->'msbuild $(MSBuildThisFileDirectory)RunTests.targets %(_BinLog) /t:%(Identity) &amp;')" />
162+
<_Commands Include="wait" />
163+
<_Commands Include="exit 0" />
164+
</ItemGroup>
165+
<PropertyGroup>
166+
<_ParallelTargets>$(MSBuildThisFileDirectory)..\..\bin\Test$(Configuration)\parallel-targets.sh</_ParallelTargets>
167+
</PropertyGroup>
168+
<WriteLinesToFile
169+
File="$(_ParallelTargets)"
170+
Lines="@(_Commands)"
171+
Overwrite="True"
172+
/>
173+
<Exec
174+
Condition=" '$(HostOS)' != 'Windows' "
175+
ContinueOnError="ErrorAndContinue"
176+
WorkingDirectory="$(_TopDir)"
177+
Command="bash $(_ParallelTargets)"
178+
/>
153179
</Target>
154180
</Project>
155-

0 commit comments

Comments
 (0)