Skip to content

Commit 5f1494f

Browse files
committed
Added test to verify that dispose has completed.
1 parent ff68b38 commit 5f1494f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Renci.SshNet.Tests/Classes/Sftp/SftpFileReaderTest_DisposeShouldUnblockReadAndReadAhead.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ public class SftpFileReaderTest_DisposeShouldUnblockReadAndReadAhead : SftpFileR
2222
private SftpCloseAsyncResult _closeAsyncResult;
2323
private SftpFileReader _reader;
2424
private ObjectDisposedException _actualException;
25+
private ManualResetEvent _disposeCompleted;
26+
27+
[TestCleanup]
28+
public void TearDown()
29+
{
30+
if (_disposeCompleted != null)
31+
{
32+
_disposeCompleted.Dispose();
33+
}
34+
}
2535

2636
protected override void SetupData()
2737
{
@@ -32,6 +42,7 @@ protected override void SetupData()
3242
_waitHandleArray = new WaitHandle[2];
3343
_operationTimeout = random.Next(10000, 20000);
3444
_closeAsyncResult = new SftpCloseAsyncResult(null, null);
45+
_disposeCompleted = new ManualResetEvent(false);
3546
}
3647

3748
protected override void SetupMocks()
@@ -74,6 +85,7 @@ protected override void Act()
7485
{
7586
Thread.Sleep(500);
7687
_reader.Dispose();
88+
_disposeCompleted.Set();
7789
});
7890

7991
try
@@ -87,6 +99,12 @@ protected override void Act()
8799
}
88100
}
89101

102+
[TestMethod]
103+
public void DisposeShouldHaveCompleted()
104+
{
105+
Assert.IsTrue(_disposeCompleted.WaitOne(0));
106+
}
107+
90108
[TestMethod]
91109
public void ReadShouldHaveThrownObjectDisposedException()
92110
{

src/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<DefineConstants>TRACE;DEBUG;FEATURE_THREAD_COUNTDOWNEVENT</DefineConstants>
2222
<ErrorReport>prompt</ErrorReport>
2323
<WarningLevel>4</WarningLevel>
24+
<LangVersion>5</LangVersion>
2425
</PropertyGroup>
2526
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2627
<DebugType>pdbonly</DebugType>

0 commit comments

Comments
 (0)