Skip to content

Commit

Permalink
Merge pull request dotnet#448 from YingP99/concurrtests
Browse files Browse the repository at this point in the history
Enable more System.Collections.Concurrent tests
  • Loading branch information
YingP99 committed Jan 23, 2015
2 parents 82ada4b + b9e4acf commit 1e10b82
Show file tree
Hide file tree
Showing 13 changed files with 3,774 additions and 313 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@ public static void InternalCancellation_CompleteAdding_Negative()

Task.Run(() => coll1.CompleteAdding());
//call Take.. it should wake up with an OCE. when CompleteAdding() is called.
Assert.Throws<InvalidOperationException>(
() => coll1.Take());
// "InternalCancellation_WakingUpTake: an IOE should be thrown if CompleteAdding occurs during blocking Take()");
Assert.Throws<InvalidOperationException>(
() => coll1.Add(1));
// "InternalCancellation_WakingUpAdd: an InvalidOpEx should be thrown if CompleteAdding occurs during blocking Add()");
Assert.Throws<InvalidOperationException>(
() => coll1.TryAdd(1, 1000000)); //an indefinite wait to add.. 1000 seconds.
// "InternalCancellation_WakingUpTryAdd: an InvalidOpEx should be thrown if CompleteAdding occurs during blocking Add()");
Assert.Throws<InvalidOperationException>(() => coll1.Take());
// "InternalCancellation_WakingUpTake: an IOE should be thrown if CompleteAdding occurs during blocking Take()");
Assert.Throws<InvalidOperationException>(() => coll1.Add(1));
// "InternalCancellation_WakingUpAdd: an InvalidOpEx should be thrown if CompleteAdding occurs during blocking Add()");
Assert.Throws<InvalidOperationException>(() => coll1.TryAdd(1, 1000000)); //an indefinite wait to add.. 1000 seconds.
// "InternalCancellation_WakingUpTryAdd: an InvalidOpEx should be thrown if CompleteAdding occurs during blocking Add()");
}

//This tests that Take/TryTake wake up correctly if CompleteAdding() is called while the taker is waiting.
Expand All @@ -43,8 +40,6 @@ public static void InternalCancellation_WakingUpTryTake()
});

int item;
Assert.False(coll1.IsAddingCompleted,
"InternalCancellation_WakingUpTryTake: At this point CompleteAdding should not have occurred.");
bool tookItem = coll1.TryTake(out item, 1000000); // wait essentially indefinitely. 1000seconds.
Assert.False(tookItem,
"InternalCancellation_WakingUpTryTake: TryTake should wake up with tookItem=false.");
Expand Down Expand Up @@ -92,9 +87,8 @@ public static void ExternalCancel_Negative()
Task.Run(() => cs.Cancel());

int item;

EnsureOperationCanceledExceptionThrown(
() => bc.Take(cs.Token), cs.Token,
() => bc.Take(cs.Token), cs.Token,
"ExternalCancel_Take: The operation should wake up via token cancellation.");
EnsureOperationCanceledExceptionThrown(
() => bc.TryTake(out item, 100000, cs.Token), cs.Token,
Expand Down Expand Up @@ -167,11 +161,11 @@ public static void ExternalCancel_GetConsumingEnumerable()
{
BlockingCollection<int> bc = new BlockingCollection<int>();
CancellationTokenSource cs = new CancellationTokenSource();
new Task(() =>
Task.Run(() =>
{
Task.WaitAll(Task.Delay(100));
cs.Cancel();
}).Start();
});

IEnumerable<int> enumerable = bc.GetConsumingEnumerable(cs.Token);

Expand Down
Loading

0 comments on commit 1e10b82

Please sign in to comment.