Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit c4aad9a

Browse files
committed
Fix threading when running unit tests
1 parent dcdd415 commit c4aad9a

File tree

7 files changed

+27
-6
lines changed

7 files changed

+27
-6
lines changed

src/GitHub.App/Services/RepositoryCloneService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.VisualStudio.Shell;
88
using NLog;
99
using Rothko;
10+
using GitHub.Helpers;
1011

1112
namespace GitHub.Services
1213
{
@@ -48,7 +49,7 @@ public IObservable<Unit> CloneRepository(string cloneUrl, string repositoryName,
4849

4950
// Once we've done IO switch to the main thread to call vsGitServices.Clone() as this must be
5051
// called on the main thread.
51-
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
52+
await ThreadingHelper.SwitchToMainThreadAsync();
5253

5354
try
5455
{

src/GitHub.Exports/GitHub.Exports.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@
9696
<HintPath>..\..\packages\Microsoft.VisualStudio.TextManager.Interop.8.0.8.0.50727\lib\Microsoft.VisualStudio.TextManager.Interop.8.0.dll</HintPath>
9797
<Private>True</Private>
9898
</Reference>
99+
<Reference Include="Microsoft.VisualStudio.Threading, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
100+
<HintPath>..\..\packages\Microsoft.VisualStudio.Threading.14.1.131\lib\net45\Microsoft.VisualStudio.Threading.dll</HintPath>
101+
<Private>True</Private>
102+
</Reference>
99103
<Reference Include="PresentationCore" />
100104
<Reference Include="PresentationFramework" />
101105
<Reference Include="System" />
@@ -133,6 +137,7 @@
133137
<Compile Include="Extensions\PropertyNotifierExtensions.cs" />
134138
<Compile Include="Extensions\SimpleRepositoryModelExtensions.cs" />
135139
<Compile Include="Helpers\SettingsStore.cs" />
140+
<Compile Include="Helpers\ThreadingHelper.cs" />
136141
<Compile Include="Info\ApplicationInfo.cs" />
137142
<Compile Include="Models\BranchModel.cs" />
138143
<Compile Include="Models\IAccount.cs" />
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Threading.Tasks;
2+
using ThreadHelper = Microsoft.VisualStudio.Shell.ThreadHelper;
3+
using GitHub.Extensions;
4+
5+
namespace GitHub.Helpers
6+
{
7+
public static class ThreadingHelper
8+
{
9+
public async static Task SwitchToMainThreadAsync()
10+
{
11+
if (!Guard.InUnitTestRunner())
12+
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
13+
}
14+
}
15+
}

src/GitHub.Exports/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<package id="Microsoft.VisualStudio.Shell.Interop.9.0" version="9.0.30729" targetFramework="net461" />
1111
<package id="Microsoft.VisualStudio.TextManager.Interop" version="7.10.6070" targetFramework="net461" />
1212
<package id="Microsoft.VisualStudio.TextManager.Interop.8.0" version="8.0.50727" targetFramework="net461" />
13+
<package id="Microsoft.VisualStudio.Threading" version="14.1.131" targetFramework="net461" />
1314
<package id="SimpleJson" version="0.38.0" targetFramework="net461" />
1415
<package id="VSSDK.ComponentModelHost" version="12.0.4" targetFramework="net461" />
1516
<package id="VSSDK.IDE.12" version="12.0.4" targetFramework="net461" />

src/GitHub.Extensions/Guard.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static void ArgumentInRange(int value, int minValue, int maxValue, string
9090
}
9191

9292
// Borrowed from Splat.
93-
static bool InUnitTestRunner()
93+
public static bool InUnitTestRunner()
9494
{
9595
return Splat.ModeDetector.InUnitTestRunner();
9696
}

src/GitHub.VisualStudio/GitHubPackage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async Task InitializeMenus()
6262
{
6363
var menus = await GetServiceAsync(typeof(IMenuProvider)) as IMenuProvider;
6464

65-
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
65+
await ThreadingHelper.SwitchToMainThreadAsync();
6666

6767
foreach (var menu in menus.Menus)
6868
serviceProvider.AddCommandHandler(menu.Guid, menu.CmdId, (s, e) => menu.Activate());

src/GitHub.VisualStudio/Services/UsageTracker.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
using System.Windows.Threading;
88
using GitHub.Models;
99
using GitHub.Settings;
10-
using Microsoft.VisualStudio.ComponentModelHost;
11-
using Microsoft.VisualStudio.Shell;
1210
using Task = System.Threading.Tasks.Task;
1311
using GitHub.Extensions;
1412
using System.Threading.Tasks;
13+
using GitHub.Helpers;
1514

1615
namespace GitHub.Services
1716
{
@@ -142,7 +141,7 @@ async Task Initialize()
142141
// improve the startup time of the extension.
143142
if (userSettings == null)
144143
{
145-
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
144+
await ThreadingHelper.SwitchToMainThreadAsync();
146145

147146
client = uiProvider.GetService<IMetricsService>();
148147
connectionManager = uiProvider.GetService<IConnectionManager>();

0 commit comments

Comments
 (0)