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

Commit bf005fb

Browse files
Let First/FirstOrDefault combinatorial accept exception.
1 parent b92843e commit bf005fb

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

src/System.Linq.Parallel/tests/Combinatorial/FailingParallelQueryCombinationTests.cs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,23 @@ public static void First_Predicate_None(Labeled<Operation> source, Labeled<Opera
9595
[MemberData(nameof(OrderFailingOperators))]
9696
public static void First_AggregateException(Labeled<Operation> source, Labeled<Operation> operation)
9797
{
98-
// Concat seems able to return the first element when the left query does not fail ("first" query).
99-
// This test might be flaky in the case that it decides to run the right query too...
10098
if (operation.ToString().Contains("Concat-Left"))
10199
{
102-
Assert.InRange(operation.Item(DefaultStart, DefaultSize, source.Item).First(), DefaultStart, DefaultStart + DefaultSize);
100+
// The vast majority of the time, the operation returns a result instead of failing.
101+
// Sufficient cores on a test machine may make the optimizer start enumerating the results.
102+
int? result = null;
103+
var exception = Record.Exception(() => { result = operation.Item(DefaultStart, DefaultSize, source.Item).First(); });
104+
if (result.HasValue)
105+
{
106+
Assert.Null(exception);
107+
Assert.InRange(result.Value, DefaultStart, DefaultStart + DefaultSize);
108+
}
109+
else
110+
{
111+
Assert.NotNull(exception);
112+
var ae = Assert.IsType<AggregateException>(exception);
113+
Assert.All(ae.InnerExceptions, e => Assert.IsType<DeliberateTestException>(e));
114+
}
103115
}
104116
else
105117
{
@@ -115,11 +127,23 @@ public static void First_AggregateException(Labeled<Operation> source, Labeled<O
115127
[MemberData(nameof(OrderFailingOperators))]
116128
public static void FirstOrDefault_AggregateException(Labeled<Operation> source, Labeled<Operation> operation)
117129
{
118-
// Concat seems able to return the first element when the left query does not fail ("first" query).
119-
// This test might be flaky in the case that it decides to run the right query too...
120130
if (operation.ToString().Contains("Concat-Left"))
121131
{
122-
Assert.InRange(operation.Item(DefaultStart, DefaultSize, source.Item).FirstOrDefault(), DefaultStart, DefaultStart + DefaultSize);
132+
// The vast majority of the time, the operation returns a result instead of failing.
133+
// Sufficient cores on a test machine may make the optimizer start enumerating the results.
134+
int? result = null;
135+
var exception = Record.Exception(() => { result = operation.Item(DefaultStart, DefaultSize, source.Item).FirstOrDefault(); });
136+
if (result.HasValue)
137+
{
138+
Assert.Null(exception);
139+
Assert.InRange(result.Value, DefaultStart, DefaultStart + DefaultSize);
140+
}
141+
else
142+
{
143+
Assert.NotNull(exception);
144+
var ae = Assert.IsType<AggregateException>(exception);
145+
Assert.All(ae.InnerExceptions, e => Assert.IsType<DeliberateTestException>(e));
146+
}
123147
}
124148
else
125149
{

0 commit comments

Comments
 (0)