-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: users for alias not balanced across threads (#90)
This is required due to the fact that, if tests are running with process or AppDomain isolation, all of the tests will enumerate through the users in the same order. Shuffling the enumerators is an approximation that saves having to find a way to synchronise between AppDomains or processes.
- Loading branch information
Showing
2 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
bindings/src/Capgemini.PowerApps.SpecFlowBindings/Extensions/IListExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
namespace Capgemini.PowerApps.SpecFlowBindings.Extensions | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
/// <summary> | ||
/// Extensions for <see cref="IList{T}"/>. | ||
/// </summary> | ||
internal static class IListExtensions | ||
{ | ||
private static readonly Random Rand = new Random(); | ||
|
||
/// <summary> | ||
/// Randomises the order of a list. | ||
/// </summary> | ||
/// <typeparam name="T">The type of list items.</typeparam> | ||
/// <param name="list">The list.</param> | ||
/// <returns>The shuffled list.</returns> | ||
internal static IList<T> Shuffle<T>(this IList<T> list) | ||
{ | ||
var n = list.Count; | ||
|
||
while (n > 1) | ||
{ | ||
n--; | ||
var k = Rand.Next(n + 1); | ||
T value = list[k]; | ||
list[k] = list[n]; | ||
list[n] = value; | ||
} | ||
|
||
return list; | ||
} | ||
} | ||
} |