You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2021/12/22 09:28:13 UTC
[lucenenet] branch master updated (93cd1e9 -> afc94c6)
This is an automated email from the ASF dual-hosted git repository.
nightowl888 pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git.
from 93cd1e9 BREAKING: Removed (more) unnecessary nullable value types (see #574 and #581) (#583)
new 8ae11fd Lucene.Net.Util.RandomizedContext: Use an underscore to prefix the property name to hide it from Test Explorer
new afc94c6 Lucene.Net.TestFramework: Changed RandomSeedAttribute to accept a string and adjusted LuceneRandomSeedInitializer to ignore any value after a colon, to allow future strings to have multiple seed values (as Lucene does) without breaking compatibility.
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../Support/Util/LuceneRandomSeedInitializer.cs | 71 ++++++++++++++--------
.../Support/Util/RandomSeedAttribute.cs | 19 ++----
.../Support/Util/RandomizedContext.cs | 3 +-
.../Util/LuceneTestCase.cs | 2 +-
4 files changed, 56 insertions(+), 39 deletions(-)
[lucenenet] 02/02: Lucene.Net.TestFramework: Changed RandomSeedAttribute to accept a string and adjusted LuceneRandomSeedInitializer to ignore any value after a colon, to allow future strings to have multiple seed values (as Lucene does) without breaking compatibility.
Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git
commit afc94c6521a3c3202e3b5658427b122bf121ee81
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Wed Dec 22 15:43:01 2021 +0700
Lucene.Net.TestFramework: Changed RandomSeedAttribute to accept a string and adjusted LuceneRandomSeedInitializer to ignore any value after a colon, to allow future strings to have multiple seed values (as Lucene does) without breaking compatibility.
---
.../Support/Util/LuceneRandomSeedInitializer.cs | 71 ++++++++++++++--------
.../Support/Util/RandomSeedAttribute.cs | 19 ++----
.../Util/LuceneTestCase.cs | 2 +-
3 files changed, 54 insertions(+), 38 deletions(-)
diff --git a/src/Lucene.Net.TestFramework/Support/Util/LuceneRandomSeedInitializer.cs b/src/Lucene.Net.TestFramework/Support/Util/LuceneRandomSeedInitializer.cs
index c715aab..70a5737 100644
--- a/src/Lucene.Net.TestFramework/Support/Util/LuceneRandomSeedInitializer.cs
+++ b/src/Lucene.Net.TestFramework/Support/Util/LuceneRandomSeedInitializer.cs
@@ -34,6 +34,7 @@ namespace Lucene.Net.Util
private J2N.Randomizer random;
private long initialSeed;
+ private long? testSeed;
/// <summary>
/// Tries to get the random seed from either a <see cref="RandomSeedAttribute"/> or the "tests:seed" system property.
@@ -43,43 +44,63 @@ namespace Lucene.Net.Util
/// <param name="seed">The random seed for a new <see cref="Random"/> instance.
/// Note this is a subclass of <see cref="Random"/>, since the default doesn't produce consistent results across platforms.</param>
/// <returns><c>true</c> if the seed was found in context; <c>false</c> if the seed was generated.</returns>
- private bool TryGetRandomSeedFromContext(Test test, out long seed)
+ private bool TryGetRandomSeedsFromContext(Test test, out long seed, out long? testSeed)
{
- bool generate;
- seed = 0;
+ //bool generate;
+ seed = default;
+ testSeed = default;
+ string seedAsString;
+
var randomSeedAttribute = (RandomSeedAttribute)test.TypeInfo.Assembly
.GetCustomAttributes(typeof(RandomSeedAttribute), inherit: false)
.FirstOrDefault();
if (randomSeedAttribute != null)
{
- seed = randomSeedAttribute.RandomSeed;
- generate = false;
+ seedAsString = randomSeedAttribute.RandomSeed;
+ //generate = false;
}
else
{
// For now, ignore anything NUnit3TestAdapter does, because it is messing up repeatable runs.
- var seedAsString = SystemProperties.GetProperty("tests:seed", null);
- if (seedAsString is null || "random".Equals(seedAsString, StringComparison.OrdinalIgnoreCase))
- {
- generate = true;
- }
- else if (J2N.Numerics.Int64.TryParse(seedAsString, 16, out seed))
- {
- generate = false;
- }
- else
+ seedAsString = SystemProperties.GetProperty("tests:seed", null);
+ }
+
+ if (seedAsString is null || "random".Equals(seedAsString, StringComparison.OrdinalIgnoreCase))
+ {
+ //generate = true;
+ return false;
+ }
+
+ int colonIndex = seedAsString.IndexOf(':');
+ if (colonIndex != -1)
+ {
+ if (!J2N.Numerics.Int64.TryParse(seedAsString, 0, colonIndex, radix: 16, out seed))
{
- generate = true;
test.MakeInvalid(RANDOM_SEED_PARAMS_MSG);
+ return false;
}
- }
- if (generate)
+ // LUCENENET TODO: For now, we are ignoring anything after a colon in the string, but logically it seems like
+ // a second seed would be to set the a test so the RandomAttribute fails on the first iteration. Lucene uses a compound
+ // seed, but it isn't clear from analyzing the source how it is used, just that it can contain any number of colon delimited
+ // values. If we ignore now, we leave the door open for adding a compound seed in the most sensible way later without breaking
+ // the current version when the change is introduced.
+ //if (!J2N.Numerics.Int64.TryParse(seedAsString, colonIndex + 1, seedAsString.Length - (colonIndex + 1), radix: 16, out long testSeedValue))
+ //{
+ // test.MakeInvalid(RANDOM_SEED_PARAMS_MSG);
+ // return false;
+ //}
+
+ //testSeed = testSeedValue;
+ return true;
+ }
+ else if (J2N.Numerics.Int64.TryParse(seedAsString, radix: 16, out seed))
{
- seed = new J2N.Randomizer().NextInt64();
- return false;
+ return true;
}
- return true;
+
+ test.MakeInvalid(RANDOM_SEED_PARAMS_MSG);
+ return false;
}
/// <summary>
@@ -94,7 +115,9 @@ namespace Lucene.Net.Util
if (fixture is null)
throw new ArgumentNullException(nameof(fixture));
- TryGetRandomSeedFromContext(fixture, out initialSeed); // NOTE: This sets the initialSeed field for this class.
+ if (!TryGetRandomSeedsFromContext(fixture, out initialSeed, out testSeed)) // NOTE: This sets the initialSeed and testSeed fields for this class.
+ initialSeed = new J2N.Randomizer().NextInt64(); // Seed not configured or explicitly set to "random", so auto-generate
+
random = new J2N.Randomizer(initialSeed + seedOffset);
int goodFastHashSeed = (int)initialSeed * 31; // LUCENENET: Multiplying 31 to remove the possility of a collision with the test framework while still using a deterministic number.
@@ -108,7 +131,7 @@ namespace Lucene.Net.Util
// result when there are filters applied.
// Generate a new long value that is the seed for this specific test.
- return InitializeTestFixture(fixture, new RandomizedContext(fixture, testAssembly, initialSeed, random.NextInt64()));
+ return InitializeTestFixture(fixture, new RandomizedContext(fixture, testAssembly, initialSeed, testSeed ?? random.NextInt64()));
}
/// <summary>
@@ -146,7 +169,7 @@ namespace Lucene.Net.Util
test.Properties.Set(
RandomizedContext.RandomizedContextPropertyName,
// Generate a new long value that is the seed for this specific test.
- new RandomizedContext(test, testAssembly, initialSeed, random.NextInt64()));
+ new RandomizedContext(test, testAssembly, initialSeed, testSeed ?? random.NextInt64()));
if (test.HasChildren)
{
diff --git a/src/Lucene.Net.TestFramework/Support/Util/RandomSeedAttribute.cs b/src/Lucene.Net.TestFramework/Support/Util/RandomSeedAttribute.cs
index 9b15af1..7c35d88 100644
--- a/src/Lucene.Net.TestFramework/Support/Util/RandomSeedAttribute.cs
+++ b/src/Lucene.Net.TestFramework/Support/Util/RandomSeedAttribute.cs
@@ -28,25 +28,18 @@ namespace Lucene.Net.Util
/// <summary>
/// Construct a <see cref="RandomSeedAttribute"/> with a specific random seed value.
/// </summary>
- /// <param name="randomSeed">A <see cref="long"/> value that represents the initial random seed to use to run the tests.</param>
- public RandomSeedAttribute(long randomSeed)
+ /// <param name="randomSeed">A <see cref="string"/> value that represents the initial random seed to use to run the tests.
+ /// The seed is a hexadecimal string representation of a <see cref="long"/> value.
+ /// <para/>
+ /// <b>NOTE:</b> For future expansion, the string may include other values as well using ":" as delimiters.</param>
+ public RandomSeedAttribute(string randomSeed)
{
RandomSeed = randomSeed;
}
/// <summary>
- /// Construct a <see cref="RandomSeedAttribute"/> with a specific random seed value.
- /// </summary>
- /// <param name="randomSeed">A <see cref="ulong"/> value that represents the initial random seed to use to run the tests.</param>
- [CLSCompliant(false)]
- public RandomSeedAttribute(ulong randomSeed)
- {
- RandomSeed = unchecked((long)randomSeed);
- }
-
- /// <summary>
/// The random seed value.
/// </summary>
- public long RandomSeed { get; private set; }
+ public string RandomSeed { get; private set; }
}
}
diff --git a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
index 4a3292e..f42baaa 100644
--- a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
+++ b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
@@ -1032,7 +1032,7 @@ namespace Lucene.Net.Util
message = result.Message + $"\n\nTo reproduce this test result:\n\n" +
$"Option 1:\n\n" +
$" Apply the following assembly-level attributes:\n\n" +
- $"[assembly: Lucene.Net.Util.RandomSeed({RandomizedContext.CurrentContext.RandomSeedAsHex}L)]\n" +
+ $"[assembly: Lucene.Net.Util.RandomSeed(\"{RandomizedContext.CurrentContext.RandomSeedAsHex}\")]\n" +
$"[assembly: NUnit.Framework.SetCulture(\"{Thread.CurrentThread.CurrentCulture.Name}\")]\n\n" +
$"Option 2:\n\n" +
$" Use the following .runsettings file:\n\n" +
[lucenenet] 01/02: Lucene.Net.Util.RandomizedContext: Use an underscore to prefix the property name to hide it from Test Explorer
Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git
commit 8ae11fd92e7489328b060d774c0a0bec5139372d
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Tue Dec 21 14:12:57 2021 +0700
Lucene.Net.Util.RandomizedContext: Use an underscore to prefix the property name to hide it from Test Explorer
---
src/Lucene.Net.TestFramework/Support/Util/RandomizedContext.cs | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/Lucene.Net.TestFramework/Support/Util/RandomizedContext.cs b/src/Lucene.Net.TestFramework/Support/Util/RandomizedContext.cs
index 8e68126..22b6aec 100644
--- a/src/Lucene.Net.TestFramework/Support/Util/RandomizedContext.cs
+++ b/src/Lucene.Net.TestFramework/Support/Util/RandomizedContext.cs
@@ -27,7 +27,8 @@ namespace Lucene.Net.Util
/// </summary>
internal class RandomizedContext
{
- internal const string RandomizedContextPropertyName = "RandomizedContext";
+ // LUCENENET NOTE: Using an underscore to prefix the name hides it from "traits" in Test Explorer
+ internal const string RandomizedContextPropertyName = "_RandomizedContext";
private Random randomGenerator;
private readonly Test currentTest;