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

Commit 40779a5

Browse files
committed
Fix PLINQ modes tests to not timeout or deadlock
The tests for PLINQ's WithExecutionMode were employing a technique to try to verify that multiple workers were indeed participating in the query: the processing of one element would block until another element was processed. This technique was then applied to queries expected to employ parallelism in their processing. However, even readily parallelizable queries may in some circumstances end up being processed sequentially. This fix changes the parallel verification to instead simply track the IDs of tasks involved in the processing. With PLINQ's current implementation, there will be one task spun up to process each partition, and so counting the number of unique task IDs involved yields the number of tasks that actually did processing; by removing the blocking, we also remove the need for this to be outer loop. This in and of itself is insufficient, though, as depending on the data source, all of the data could still end up in a single partition; to fix that, the test is changed to only operate over data sources that do fixed partitioning, namely those involving non-load balanced ranges. With these changes, we can then significantly reduce the number of elements involved in the tests, as they become entirely deterministic with regards to what data is in which partition. And we can easily add a test that was previously missing: verifying that certain queries are not parallelized and end up running sequentially.
1 parent 0a6a0d1 commit 40779a5

File tree

2 files changed

+105
-158
lines changed

2 files changed

+105
-158
lines changed

src/System.Linq.Parallel/tests/Helpers/Functions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33
using System;
4+
using System.Collections.Generic;
45
using System.Threading;
56
using Xunit;
67

@@ -40,5 +41,10 @@ public static void AssertIsCanceled(CancellationTokenSource source, Action query
4041
OperationCanceledException oce = Assert.Throws<OperationCanceledException>(query);
4142
Assert.Equal(source.Token, oce.CancellationToken);
4243
}
44+
45+
public static void Enumerate<T>(this IEnumerable<T> e)
46+
{
47+
foreach (var x in e) { }
48+
}
4349
}
4450
}

0 commit comments

Comments
 (0)