Browse Source

Second attempt to fix hang when closing SharpDevelop with a solution and the package management console open.

pull/16/merge
Matt Ward 15 years ago
parent
commit
7962901968
  1. 2
      src/AddIns/Misc/PackageManagement/Project/Src/Scripting/IThread.cs
  2. 6
      src/AddIns/Misc/PackageManagement/Project/Src/Scripting/PackageManagementConsoleHost.cs
  3. 6
      src/AddIns/Misc/PackageManagement/Project/Src/Scripting/PackageManagementConsolePad.cs
  4. 9
      src/AddIns/Misc/PackageManagement/Project/Src/Scripting/PackageManagementConsoleViewModel.cs
  5. 4
      src/AddIns/Misc/PackageManagement/Project/Src/Scripting/PackageManagementThread.cs
  6. 7
      src/AddIns/Misc/PackageManagement/Test/Src/Helpers/FakeThread.cs
  7. 43
      src/AddIns/Misc/PackageManagement/Test/Src/Scripting/PackageManagementConsoleHostTests.cs
  8. 24
      src/AddIns/Misc/PackageManagement/Test/Src/Scripting/PackageManagementConsoleViewModelTests.cs

2
src/AddIns/Misc/PackageManagement/Project/Src/Scripting/IThread.cs

@ -8,6 +8,6 @@ namespace ICSharpCode.PackageManagement.Scripting
public interface IThread public interface IThread
{ {
void Start(); void Start();
void Join(); bool Join(int milliescondsTimeout);
} }
} }

6
src/AddIns/Misc/PackageManagement/Project/Src/Scripting/PackageManagementConsoleHost.cs

@ -61,8 +61,10 @@ namespace ICSharpCode.PackageManagement.Scripting
ShutdownConsole(); ShutdownConsole();
if (thread != null) { if (thread != null) {
thread.Join(); if (thread.Join(100)) {
thread = null; thread = null;
IsRunning = false;
}
} }
} }

6
src/AddIns/Misc/PackageManagement/Project/Src/Scripting/PackageManagementConsolePad.cs

@ -25,9 +25,9 @@ namespace ICSharpCode.PackageManagement.Scripting
public override void Dispose() public override void Dispose()
{ {
if (viewModel != null) { if (viewModel != null) {
viewModel.ShutdownConsole(); while (!viewModel.ShutdownConsole()) {
DoEvents(); DoEvents();
viewModel.Dispose(); }
viewModel = null; viewModel = null;
} }
} }

9
src/AddIns/Misc/PackageManagement/Project/Src/Scripting/PackageManagementConsoleViewModel.cs

@ -228,14 +228,11 @@ namespace ICSharpCode.PackageManagement.Scripting
get { return packageManagementConsole.TextEditor; } get { return packageManagementConsole.TextEditor; }
} }
public void Dispose() public bool ShutdownConsole()
{
consoleHost.Dispose();
}
public void ShutdownConsole()
{ {
consoleHost.ShutdownConsole(); consoleHost.ShutdownConsole();
consoleHost.Dispose();
return !consoleHost.IsRunning;
} }
} }
} }

4
src/AddIns/Misc/PackageManagement/Project/Src/Scripting/PackageManagementThread.cs

@ -20,9 +20,9 @@ namespace ICSharpCode.PackageManagement.Scripting
thread.Start(); thread.Start();
} }
public void Join() public bool Join(int milliescondsTimeout)
{ {
thread.Join(); return thread.Join(milliescondsTimeout);
} }
} }
} }

7
src/AddIns/Misc/PackageManagement/Test/Src/Helpers/FakeThread.cs

@ -17,9 +17,14 @@ namespace PackageManagement.Tests.Helpers
IsStartCalled = true; IsStartCalled = true;
} }
public void Join() public int TimeoutPassedToJoin;
public bool JoinReturnValue = true;
public bool Join(int milliescondsTimeout)
{ {
IsJoinCalled = true; IsJoinCalled = true;
TimeoutPassedToJoin = milliescondsTimeout;
return JoinReturnValue;
} }
} }
} }

43
src/AddIns/Misc/PackageManagement/Test/Src/Scripting/PackageManagementConsoleHostTests.cs

@ -67,13 +67,16 @@ namespace PackageManagement.Tests.Scripting
} }
[Test] [Test]
public void Dispose_ConsoleHostRunCalled_ThreadJoinIsCalled() public void Dispose_ConsoleHostRunCalled_ThreadJoinIsCalledWithTimeout()
{ {
CreateHost(); CreateHost();
host.Run(); host.Run();
host.Dispose(); host.Dispose();
Assert.IsTrue(host.FakeThread.IsJoinCalled); int timeout = host.FakeThread.TimeoutPassedToJoin;
int expectedTimeout = 100; //ms
Assert.AreEqual(expectedTimeout, timeout);
} }
[Test] [Test]
@ -89,6 +92,42 @@ namespace PackageManagement.Tests.Scripting
Assert.IsFalse(host.FakeThread.IsJoinCalled); Assert.IsFalse(host.FakeThread.IsJoinCalled);
} }
[Test]
public void Dispose_DisposeCalledTwiceAfterConsoleHostIsRunAndThreadDoesNotFinishOnFirstCall_ThreadJoinIsCalledTwice()
{
CreateHost();
host.Run();
host.FakeThread.JoinReturnValue = false;
host.Dispose();
host.FakeThread.IsJoinCalled = false;
host.Dispose();
Assert.IsTrue(host.FakeThread.IsJoinCalled);
}
[Test]
public void IsRunning_DisposedAndThreadFinishes_ReturnsFalse()
{
CreateHost();
host.Run();
host.FakeThread.JoinReturnValue = true;
host.Dispose();
Assert.IsFalse(host.IsRunning);
}
[Test]
public void IsRunning_DisposedButThreadDidNotFinish_ReturnsTrue()
{
CreateHost();
host.Run();
host.FakeThread.JoinReturnValue = false;
host.Dispose();
Assert.IsTrue(host.IsRunning);
}
[Test] [Test]
public void Run_ConsoleExitsOnFirstRead_PowerShellHostIsCreated() public void Run_ConsoleExitsOnFirstRead_PowerShellHostIsCreated()
{ {

24
src/AddIns/Misc/PackageManagement/Test/Src/Scripting/PackageManagementConsoleViewModelTests.cs

@ -459,10 +459,10 @@ namespace PackageManagement.Tests.Scripting
} }
[Test] [Test]
public void Dispose_ViewModelDisposed_ConsoleIsDisposed() public void ShutdownConsole_ViewModelShuttingDown_ConsoleIsDisposed()
{ {
CreateViewModel(); CreateViewModel();
viewModel.Dispose(); viewModel.ShutdownConsole();
Assert.IsTrue(consoleHost.IsDisposeCalled); Assert.IsTrue(consoleHost.IsDisposeCalled);
} }
@ -511,6 +511,26 @@ namespace PackageManagement.Tests.Scripting
Assert.IsTrue(shutdownConsole); Assert.IsTrue(shutdownConsole);
} }
[Test]
public void ShutdownConsole_ConsoleHostIsRunningIsTrue_ReturnsFalse()
{
CreateViewModel();
consoleHost.IsRunning = true;
bool shutdownConsole = viewModel.ShutdownConsole();
Assert.IsFalse(shutdownConsole);
}
[Test]
public void ShutdownConsole_ConsoleHostIsRunningIsFalse_ReturnsTrue()
{
CreateViewModel();
consoleHost.IsRunning = false;
bool shutdownConsole = viewModel.ShutdownConsole();
Assert.IsTrue(shutdownConsole);
}
[Test] [Test]
public void ActivePackageSource_SetToNullWhenPackageSourcesCleared_DoesNotThrowNullReferenceException() public void ActivePackageSource_SetToNullWhenPackageSourcesCleared_DoesNotThrowNullReferenceException()
{ {

Loading…
Cancel
Save