Skip to content

[MSBuildDeviceIntegration] Give each test a unique package name. - #5551

Merged
jonpryor merged 10 commits into
dotnet:masterfrom
dellis1972:uniquetst
Feb 26, 2021
Merged

jonpryor merged 10 commits into
dotnet:masterfrom
dellis1972:uniquetst

Conversation

@dellis1972

@dellis1972 dellis1972 commented Jan 27, 2021 •

Copy link
Copy Markdown
Contributor

One of the problems we might see on CI is when two tests run at the same
time on the same emulator. This can cause collisions and tests to fail
because the app was changed while the test was running.
Currently ALL of the tests user UnnamedProject.UnnamedProject as a
package name. This means they overwrite each other.

The commit introduces a new system which will
auto generate a package name based on the test name itself.
We do this by using the [CallerMethod] attribute to find out
which method called the constructor of the
XamarinAndroidApplicationProject. This is then used to construct
a unique (ish) package name in the form

com.xamarin.<TestMethodName>

This should stop collisions. As part of the process we also register each
packageName used with a static cache. We then uninstall those from the
device when the OnTimeTearDown method is called. This means the
device will be cleaned as groups of tests are run.

@dellis1972
dellis1972 force-pushed the uniquetst branch 3 times, most recently from 7ddd47a to d757c07 Compare February 12, 2021 13:11
@dellis1972 dellis1972 changed the title [MSBuildDeviceIntegration] Give each test a unique package name so stop collisions. [MSBuildDeviceIntegration] Give each test a unique package name. Feb 12, 2021
@dellis1972
dellis1972 marked this pull request as ready for review February 12, 2021 13:12
@jonpryor

Copy link
Copy Markdown
Contributor

There's one current test failure in Xamarin.Android.Build.Tests.BuildTest.MissingOrgApacheHttpClient("dx"):

…/NuGet.targets(128,5): error : Could not find file '/Users/runner/.nuget/packages/xamarin.googleplayservices.base/117.1.0/1cev9rpg.52e'. [/Users/runner/work/1/s/bin/TestRelease/temp/MissingOrgApacheHttpClientdx/UnnamedProject.csproj]

This "feels like" a possible "concurrent NuGet restore" scenario, and the declaring test fixture doesn't prevent that:

https://github.com/xamarin/xamarin-android/blob/214dd76d9441c9974775f0b29feec0d5d8d1097f/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs#L23

Restarting the tests.

dellis1972 and others added 10 commits February 24, 2021 10:01
One of the problems we might see on CI is when two tests run at the same
time on the same emulator. This can cause collisions and tests to fail
because the app was changed while the test was running.
Currently ALL of the tests user `UnnamedProject.UnnamedProject` as a
package name. This means they overwrite each other.

The commit introduces a new method `GeneratePackageName` which will
auto generate a package name based on

`com.xamarin.test<Test ID>`

where `<Test ID>` is the value we get from `TestContext.CurrentContext.Test.ID`.
We have to switch out the hyphens in the Test ID to get a valid package
name, but it will be unique. The result will be each test will have its
own package and install location. None of the tests will overwrite the
others. Addition code has been put in place for test `TearDown` to
ensure that the package is uninstalled. This is so we don't fill up the
device and run out of disk space.

From now on Device based tests should use the new method to set the
`PackageName` property.
@dellis1972

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines failed to run 1 pipeline(s).

@dellis1972

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@jonpryor
jonpryor merged commit 0de3135 into dotnet:master Feb 26, 2021
@dellis1972
dellis1972 deleted the uniquetst branch February 26, 2021 19:28
@github-actions github-actions Bot locked and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants