diff options
author | Keting Yang <ketyang@microsoft.com> | 2019-09-18 20:41:19 +0300 |
---|---|---|
committer | Keting Yang <ketyang@microsoft.com> | 2019-09-18 20:41:19 +0300 |
commit | 0de3a3e8a319606410f8898d6d0db8c7c4f7cbeb (patch) | |
tree | 30eea24f3ec3bc1fb300a2a2f651d28665627887 /main/src/addins/MonoDevelop.UnitTesting | |
parent | 1abc0b5c2336147e0cbeca63a068fd006e71b00b (diff) |
[Unit Tests] avoid running old tests in VsTestProjectTestSuite when it will be removed later
When UnitTestService is running the tests, for VsTest, it is using the old tests before all test information is refreshed.
In UnitTestGroup.Refresh(), Tests collection is accessed which triggered VsTestProjectTestSuite’s OnCreateTests(). However it will return the control to the calling thread once VsTestDiscoveryAdapter.Instance.DiscoverTestsAsync (Project); is called. This causes the tests not properly refreshed.
For the fix, a new method DiscoverTestAsync() is created, which does the same thing as old OnCreateTests() does, but returns a Task. Local variable testDiscoveryTask is created and shared by OnCreateTests() and Refresh(). We use it to know when Refresh() can return.
Diffstat (limited to 'main/src/addins/MonoDevelop.UnitTesting')
-rw-r--r-- | main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.VsTest/VsTestProjectTestSuite.cs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.VsTest/VsTestProjectTestSuite.cs b/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.VsTest/VsTestProjectTestSuite.cs index 209c82ca8a..057bbee301 100644 --- a/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.VsTest/VsTestProjectTestSuite.cs +++ b/main/src/addins/MonoDevelop.UnitTesting/MonoDevelop.UnitTesting.VsTest/VsTestProjectTestSuite.cs @@ -44,6 +44,7 @@ namespace MonoDevelop.UnitTesting.VsTest public Project Project { get; private set; } DateTime? lastBuildTime; UnitTest [] oldTests; + Task testDiscoveryTask; public VsTestProjectTestSuite (Project project) : base (project.Name, project) @@ -88,6 +89,14 @@ namespace MonoDevelop.UnitTesting.VsTest protected override async void OnCreateTests () { + if (testDiscoveryTask == null) { + testDiscoveryTask = DiscoverTestsAsync (); + } + + } + + protected async Task DiscoverTestsAsync () + { try { AddOldTests (); Status = TestStatus.Loading; @@ -118,7 +127,7 @@ namespace MonoDevelop.UnitTesting.VsTest void AddOldTests () { - if (oldTests != null) { + if (oldTests != null && Tests.Count == 0) { foreach (var test in oldTests) { Tests.Add (test); } @@ -133,6 +142,7 @@ namespace MonoDevelop.UnitTesting.VsTest void AfterBuild (object sender, BuildEventArgs args) { + testDiscoveryTask = null; DateTime? buildTime = GetAssemblyLastWriteTime (); if (RefreshRequired (buildTime)) { lastBuildTime = buildTime; @@ -154,6 +164,13 @@ namespace MonoDevelop.UnitTesting.VsTest return false; } + + public async override Task Refresh (CancellationToken ct) + { + if (testDiscoveryTask == null) + testDiscoveryTask = DiscoverTestsAsync (); + await testDiscoveryTask; + } void SaveOldTests () { |