Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Random.Shared #25021

Merged
merged 2 commits into from
Jun 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/EFCore/Storage/ExecutionStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ public abstract class ExecutionStrategy : IExecutionStrategy
/// <summary>
/// A pseudo-random number generator that can be used to vary the delay between retries.
/// </summary>
#if NET6_0_OR_GREATER
protected virtual Random Random { get; } = Random.Shared;
#else
protected virtual Random Random { get; } = new();
#endif

/// <summary>
/// The maximum number of retry attempts.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3644,7 +3644,7 @@ public virtual Task Random_next_is_not_funcletized_1(bool async)
{
return AssertQuery(
async,
ss => ss.Set<Order>().Where(o => o.OrderID < (new Random().Next() - 2147483647)));
ss => ss.Set<Order>().Where(o => o.OrderID < (Random.Shared.Next() - 2147483647)));
}

[ConditionalTheory]
Expand All @@ -3653,7 +3653,7 @@ public virtual Task Random_next_is_not_funcletized_2(bool async)
{
return AssertQuery(
async,
ss => ss.Set<Order>().Where(o => o.OrderID > new Random().Next(5)),
ss => ss.Set<Order>().Where(o => o.OrderID > Random.Shared.Next(5)),
entryCount: 830);
}

Expand All @@ -3663,7 +3663,7 @@ public virtual Task Random_next_is_not_funcletized_3(bool async)
{
return AssertQuery(
async,
ss => ss.Set<Order>().Where(o => o.OrderID > new Random().Next(0, 10)),
ss => ss.Set<Order>().Where(o => o.OrderID > Random.Shared.Next(0, 10)),
entryCount: 830);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ private static void AddExpectedFailure(string testName, string expectedException

public void Execute<TElement>(IQueryable<TElement> query, DbContext context, string testMethodName)
{
var seed = ProceduralQueryExpressionGenerator.Seed ?? new Random().Next();
var seed = ProceduralQueryExpressionGenerator.Seed ?? Random.Shared.Next();
var random = new Random(seed);
var depth = 2;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public static string CreateConnectionString(string name, string fileName = null,
{
var builder = new SqlConnectionStringBuilder(TestEnvironment.DefaultConnection)
{
MultipleActiveResultSets = multipleActiveResultSets ?? new Random().Next(0, 2) == 1, InitialCatalog = name
MultipleActiveResultSets = multipleActiveResultSets ?? Random.Shared.Next(0, 2) == 1, InitialCatalog = name
};
if (fileName != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ public ListElement(int i)
NullableInt = i;
String = i.ToString();
XNode = new NotXText(i.ToString());
Random = new Random();
Random = Random.Shared;
ByteArray = new[] { (byte)i, (byte)i, (byte)i, (byte)i };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public ListElement(int i)
Int = i;
NullableInt = i;
String = i.ToString();
Random = new Random();
Random = Random.Shared;
ByteArray = new[] { (byte)i, (byte)i, (byte)i, (byte)i };
}

Expand Down