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

Lucene.Net.TestFramework: Fixed random seed functionality so it is repeatable (Fixes #288) #547

Merged
merged 28 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d4ca8b4
Lucene.Net.TestFramework.Util.LuceneTestCase: Added message to the te…
NightOwl888 Nov 11, 2021
fa7c735
Lucene.Net.TestFramework.Util: Added customized TestFixtureAttribute,…
NightOwl888 Nov 11, 2021
2c74f2d
BREAKING: Lucene.Net.Util.StringHelper.GOOD_FAST_HASH_SEED: converted…
NightOwl888 Nov 7, 2021
90bcf55
Lucene.Net.TestFramework.Support.Util.LuceneRandomSeedInitializer: Ad…
NightOwl888 Nov 11, 2021
d150553
Lucene.Net.TestFramework.Util.LuceneTestCase: Stow Random instance in…
NightOwl888 Nov 11, 2021
f63ed4d
Lucene.Net.TestFramework: Reworked LuceneRandomSeedIntiailizer and ch…
NightOwl888 Nov 12, 2021
a4d75d3
Lucene.Net.TestFramework: Removed support for Randomizer.InitialSeed …
NightOwl888 Nov 12, 2021
80504cf
Lucene.Net.Tests.TestFramework.Support.TestApiConsistency: Added excl…
NightOwl888 Nov 13, 2021
aa3d727
Lucene.Net.TestFramework.Util.TestRuleSetupAndRestoreClassEnv: Change…
NightOwl888 Nov 14, 2021
cf685cc
Lucene.Net.TestFramework: Created RandomizedContext class to store as…
NightOwl888 Nov 14, 2021
8633f67
BREAKING: Added LuceneSetUpFixtureBuilder class to load either a subc…
NightOwl888 Nov 15, 2021
7ee4b3f
Lucene.Net.TestFramework.Util.LuceneTestCase: Only print out the deta…
NightOwl888 Nov 15, 2021
d826cc4
BREAKING: Lucene.Net.TestFramework.Util.LuceneTestCase: Deprecated Ge…
NightOwl888 Nov 16, 2021
0bc77dd
BREAKING: Lucene.Net.TestFramework.Util.AbstractBeforeAfterRule: Remo…
NightOwl888 Nov 16, 2021
d8a4440
Lucene.Net.Util.LuceneRandomSeedInitializer: Added overload of Initia…
NightOwl888 Nov 16, 2021
973f525
Lucene.Net.TestFramework.Util: Added UseTempLineDocsFileAttribute and…
NightOwl888 Nov 16, 2021
a6b88fd
Lucene.Net.TestFramework.Util.TestRuleSetupAndRestoreClassEnv: Allow …
NightOwl888 Nov 18, 2021
b512b1e
Lucene.Net.TestFramework.Util.LuceneTestCase: Updated repeat instruct…
NightOwl888 Nov 18, 2021
6446eb6
Lucene.Net.TestFramework.Analysis.BaseTokenStreamTestCase: Switched f…
NightOwl888 Nov 18, 2021
acb5efd
Lucene.Net.Tests.Analysis.Common.Analysis.Core.TestRandomChains: Swit…
NightOwl888 Nov 18, 2021
cbf0fd0
azure-pipelines.yml: set maximumAllowedFailures to 0
NightOwl888 Nov 6, 2021
987a63f
SWEEP: Marked all of the latest test failures with [AwaitsFix] attrib…
NightOwl888 Nov 19, 2021
38c026e
Lucene.Net.Classification.KNearestNeighborClassifierTest::TestPerform…
NightOwl888 Nov 19, 2021
f133e82
Lucene.Net.Index.TestIndexWriter::TestThreadInterruptDeadlock(): Adde…
NightOwl888 Nov 21, 2021
8ded01e
Lucene.Net.Tests.Join.TestJoinUtil::TestMultiValueRandomJoin(): Added…
NightOwl888 Nov 19, 2021
6d3c859
SWEEP: Changed all test instances of System.Random to J2N.Randomizer.…
NightOwl888 Nov 21, 2021
5c63995
Lucene.Net.TestFramework.Util.MethodInfoComparer: Made into singleton
NightOwl888 Nov 19, 2021
08fbeec
Lucene.Net.Classification.KNearestNeighborClassifierTest::TestPerform…
NightOwl888 Nov 22, 2021
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
44 changes: 22 additions & 22 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -336,17 +336,17 @@ stages:
osName: 'Windows'
imageName: 'windows-2019'
maximumParallelJobs: 8
maximumAllowedFailures: 2 # Maximum allowed failures for a successful build
maximumAllowedFailures: 0 # Maximum allowed failures for a successful build
Linux:
osName: 'Linux'
imageName: 'ubuntu-latest'
maximumParallelJobs: 7
maximumAllowedFailures: 2 # Maximum allowed failures for a successful build
maximumAllowedFailures: 0 # Maximum allowed failures for a successful build
macOS:
osName: 'macOS'
imageName: 'macOS-latest'
maximumParallelJobs: 7
maximumAllowedFailures: 2 # Maximum allowed failures for a successful build
maximumAllowedFailures: 0 # Maximum allowed failures for a successful build
displayName: 'Test net6.0,x64 on'
pool:
vmImage: $(imageName)
Expand All @@ -370,17 +370,17 @@ stages:
osName: 'Windows'
imageName: 'windows-2019'
maximumParallelJobs: 8
maximumAllowedFailures: 2 # Maximum allowed failures for a successful build
maximumAllowedFailures: 0 # Maximum allowed failures for a successful build
Linux:
osName: 'Linux'
imageName: 'ubuntu-latest'
maximumParallelJobs: 7
maximumAllowedFailures: 2 # Maximum allowed failures for a successful build
maximumAllowedFailures: 0 # Maximum allowed failures for a successful build
macOS:
osName: 'macOS'
imageName: 'macOS-latest'
maximumParallelJobs: 7
maximumAllowedFailures: 2 # Maximum allowed failures for a successful build
maximumAllowedFailures: 0 # Maximum allowed failures for a successful build
displayName: 'Test net6.0,x86 on'
pool:
vmImage: $(imageName)
Expand All @@ -404,17 +404,17 @@ stages:
osName: 'Windows'
imageName: 'windows-2019'
maximumParallelJobs: 8
maximumAllowedFailures: 2 # Maximum allowed failures for a successful build
maximumAllowedFailures: 0 # Maximum allowed failures for a successful build
Linux:
osName: 'Linux'
imageName: 'ubuntu-latest'
maximumParallelJobs: 7
maximumAllowedFailures: 2 # Maximum allowed failures for a successful build
maximumAllowedFailures: 0 # Maximum allowed failures for a successful build
macOS:
osName: 'macOS'
imageName: 'macOS-latest'
maximumParallelJobs: 7
maximumAllowedFailures: 2 # Maximum allowed failures for a successful build
maximumAllowedFailures: 0 # Maximum allowed failures for a successful build
displayName: 'Test net5.0,x64 on'
pool:
vmImage: $(imageName)
Expand All @@ -438,17 +438,17 @@ stages:
osName: 'Windows'
imageName: 'windows-2019'
maximumParallelJobs: 8
maximumAllowedFailures: 2 # Maximum allowed failures for a successful build
maximumAllowedFailures: 0 # Maximum allowed failures for a successful build
Linux:
osName: 'Linux'
imageName: 'ubuntu-latest'
maximumParallelJobs: 7
maximumAllowedFailures: 2 # Maximum allowed failures for a successful build
maximumAllowedFailures: 0 # Maximum allowed failures for a successful build
macOS:
osName: 'macOS'
imageName: 'macOS-latest'
maximumParallelJobs: 7
maximumAllowedFailures: 2 # Maximum allowed failures for a successful build
maximumAllowedFailures: 0 # Maximum allowed failures for a successful build
displayName: 'Test net5.0,x86 on'
pool:
vmImage: $(imageName)
Expand All @@ -472,17 +472,17 @@ stages:
osName: 'Windows'
imageName: 'windows-2019'
maximumParallelJobs: 8
maximumAllowedFailures: 2 # Maximum allowed failures for a successful build
maximumAllowedFailures: 0 # Maximum allowed failures for a successful build
Linux:
osName: 'Linux'
imageName: 'ubuntu-latest'
maximumParallelJobs: 7
maximumAllowedFailures: 2 # Maximum allowed failures for a successful build
maximumAllowedFailures: 0 # Maximum allowed failures for a successful build
macOS:
osName: 'macOS'
imageName: 'macOS-10.15' # macOS-latest should not be used here because we may get OS Darwin 19.6.0, which isn't supported fully (we get PlatformNotSupportedException).
maximumParallelJobs: 7
maximumAllowedFailures: 2 # Maximum allowed failures for a successful build
maximumAllowedFailures: 0 # Maximum allowed failures for a successful build
displayName: 'Test netcoreapp3.1,x64 on'
pool:
vmImage: $(imageName)
Expand All @@ -506,17 +506,17 @@ stages:
osName: 'Windows'
imageName: 'windows-2019'
maximumParallelJobs: 8
maximumAllowedFailures: 2 # Maximum allowed failures for a successful build
maximumAllowedFailures: 0 # Maximum allowed failures for a successful build
Linux:
osName: 'Linux'
imageName: 'ubuntu-latest'
maximumParallelJobs: 7
maximumAllowedFailures: 2 # Maximum allowed failures for a successful build
maximumAllowedFailures: 0 # Maximum allowed failures for a successful build
macOS:
osName: 'macOS'
imageName: 'macOS-10.15' # macOS-latest should not be used here because we may get OS Darwin 19.6.0, which isn't supported fully (we get PlatformNotSupportedException).
maximumParallelJobs: 7
maximumAllowedFailures: 2 # Maximum allowed failures for a successful build
maximumAllowedFailures: 0 # Maximum allowed failures for a successful build
displayName: 'Test netcoreapp3.1,x86 on'
pool:
vmImage: $(imageName)
Expand All @@ -540,7 +540,7 @@ stages:
osName: 'Windows'
imageName: 'windows-2019'
maximumParallelJobs: 8
maximumAllowedFailures: 2 # Maximum allowed failures for a successful build
maximumAllowedFailures: 0 # Maximum allowed failures for a successful build
displayName: 'Test net461,x64 on'
pool:
vmImage: $(imageName)
Expand All @@ -564,7 +564,7 @@ stages:
osName: 'Windows'
imageName: 'windows-2019'
maximumParallelJobs: 8
maximumAllowedFailures: 2 # Maximum allowed failures for a successful build
maximumAllowedFailures: 0 # Maximum allowed failures for a successful build
displayName: 'Test net461,x86 on'
pool:
vmImage: $(imageName)
Expand Down Expand Up @@ -595,7 +595,7 @@ stages:
nugetArtifactName: '$(NuGetArtifactName)'
testResultsArtifactName: '$(TestResultsArtifactName)'
maximumParallelJobs: 8
maximumAllowedFailures: 2 # Maximum allowed failures for a successful build
maximumAllowedFailures: 0 # Maximum allowed failures for a successful build

- job: Test_net48_Windows_x86 # Only run Nightly or if explicitly enabled with RunX86Tests
condition: and(succeeded(), ne(variables['RunTests'], 'false'), or(eq(variables['IsNightly'], 'true'), eq(variables['RunX86Tests'], 'true')))
Expand All @@ -612,7 +612,7 @@ stages:
nugetArtifactName: '$(NuGetArtifactName)'
testResultsArtifactName: '$(TestResultsArtifactName)'
maximumParallelJobs: 8
maximumAllowedFailures: 2 # Maximum allowed failures for a successful build
maximumAllowedFailures: 0 # Maximum allowed failures for a successful build


- stage: Publish_Stage
Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net.Benchmark/ByTask/Feeds/DocMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ public virtual void SetConfig(Config config, ContentSource source)
updateDocIDLimit = config.Get("doc.random.id.limit", -1);
if (updateDocIDLimit != -1)
{
r = new Random(179);
r = new J2N.Randomizer(179);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net.Benchmark/ByTask/Feeds/RandomFacetSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected override void Dispose(bool disposing)
public override void SetConfig(Config config)
{
base.SetConfig(config);
random = new Random(config.Get("rand.seed", 13));
random = new J2N.Randomizer(config.Get("rand.seed", 13));
maxDocFacets = config.Get("max.doc.facets", 10);
maxDims = config.Get("max.doc.facets.dims", 5);
maxFacetDepth = config.Get("max.facet.depth", 3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public override void SetConfig(Config config)
{
base.SetConfig(config);
sortRange = config.Get("sort.rng", 20000);
r = new Random(config.Get("rand.seed", 13));
r = new J2N.Randomizer(config.Get("rand.seed", 13));
}
}
}
2 changes: 1 addition & 1 deletion src/Lucene.Net.Benchmark/ByTask/Feeds/SpatialDocMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public IShape Convert(IShape shape)
double radius = radiusDegrees;
if (plusMinus > 0.0)
{
Random random = new Random(point.GetHashCode());//use hashCode so it's reproducibly random
Random random = new J2N.Randomizer(point.GetHashCode());//use hashCode so it's reproducibly random
radius += random.NextDouble() * 2 * plusMinus - plusMinus;
radius = Math.Abs(radius);//can happen if configured plusMinus > radiusDegrees
}
Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net.Expressions/JS/JavascriptCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private Expression CompileExpression()

private void BeginCompile()
{
var assemblyName = new AssemblyName("Lucene.Net.Expressions.Dynamic" + new Random().Next());
var assemblyName = new AssemblyName("Lucene.Net.Expressions.Dynamic" + Math.Abs(new J2N.Randomizer().Next()));
asmBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.RunAndCollect);

modBuilder = asmBuilder.DefineDynamicModule(assemblyName.Name + ".dll");
Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net.Suggest/Suggest/UnsortedInputIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public UnsortedInputEnumerator(IInputEnumerator source)
: base(source)
{
ords = new int[m_entries.Length];
Random random = new Random();
Random random = new J2N.Randomizer();
for (int i = 0; i < ords.Length; i++)
{
ords[i] = i;
Expand Down
29 changes: 12 additions & 17 deletions src/Lucene.Net.TestFramework/Analysis/BaseTokenStreamTestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public override void CopyTo(IAttribute target)
/// </summary>
/// <seealso cref="MockAnalyzer"/>
/// <seealso cref="MockTokenizer"/>
// LUCENENET specific - Specify to unzip the line file docs
[UseTempLineDocsFile]
public abstract class BaseTokenStreamTestCase : LuceneTestCase
#if TESTFRAMEWORK_XUNIT
, Xunit.IClassFixture<BeforeAfterClass>
Expand Down Expand Up @@ -126,13 +128,6 @@ public BaseTokenStreamTestCase(BeforeAfterClass beforeAfter)

// LUCENENET specific - de-nested CheckClearAttributesAttribute

// LUCENENET specific - Specify to unzip the line file docs
public override void BeforeClass()
{
UseTempLineDocsFile = true;
base.BeforeClass();
}

// offsetsAreCorrect also validates:
// - graph offsets are correct (all tokens leaving from
// pos X have the same startOffset; all tokens
Expand Down Expand Up @@ -715,7 +710,7 @@ public override void Run()
if (latch != null) latch.Wait();
// see the part in checkRandomData where it replays the same text again
// to verify reproducability/reuse: hopefully this would catch thread hazards.
CheckRandomData(new Random((int)seed), a, iterations, maxWordLength, useCharFilter, simple, offsetsAreCorrect, iw);
CheckRandomData(new J2N.Randomizer(seed), a, iterations, maxWordLength, useCharFilter, simple, offsetsAreCorrect, iw);
success = true;
}
catch (Exception e) when (e.IsException()) // LUCENENET TODO: This catch block can be removed because Rethrow.rethrow() simply does what its name says, but need to get rid of the FirstException functionality and fix ThreadJob so it re-throws ThreadInterruptedExcepetion first.
Expand Down Expand Up @@ -754,7 +749,7 @@ public void CheckRandomData(Random random, Analyzer a, int iterations, int maxWo
#endif
{
CheckResetException(a, "best effort");
long seed = random.Next();
long seed = random.NextInt64();
bool useCharFilter = random.NextBoolean();
Directory dir = null;
RandomIndexWriter iw = null;
Expand All @@ -769,13 +764,13 @@ public void CheckRandomData(Random random, Analyzer a, int iterations, int maxWo
#if FEATURE_INSTANCE_TESTDATA_INITIALIZATION
this,
#endif
new Random((int)seed), dir, a);
new J2N.Randomizer(seed), dir, a);
}

bool success = false;
try
{
CheckRandomData(new Random((int)seed), a, iterations, maxWordLength, useCharFilter, simple, offsetsAreCorrect, iw);
CheckRandomData(new J2N.Randomizer(seed), a, iterations, maxWordLength, useCharFilter, simple, offsetsAreCorrect, iw);
// now test with multiple threads: note we do the EXACT same thing we did before in each thread,
// so this should only really fail from another thread if its an actual thread problem
int numThreads = TestUtil.NextInt32(random, 2, 4);
Expand All @@ -785,7 +780,7 @@ public void CheckRandomData(Random random, Analyzer a, int iterations, int maxWo
{
threads[i] = new AnalysisThread(seed, startingGun, a, iterations, maxWordLength, useCharFilter, simple, offsetsAreCorrect, iw);
}

foreach (AnalysisThread thread in threads)
{
thread.Start();
Expand Down Expand Up @@ -948,7 +943,7 @@ private static void CheckRandomData(Random random, Analyzer a, int iterations, i
{
// TODO: really we should pass a random seed to
// checkAnalysisConsistency then print it here too:
Console.Error.WriteLine("TEST FAIL: useCharFilter=" + useCharFilter + " text='" + Escape(text) + "'");
Console.Error.WriteLine($"TEST FAIL (iteration {i}): useCharFilter=" + useCharFilter + " text='" + Escape(text) + "'");
throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details)
}
}
Expand Down Expand Up @@ -1201,8 +1196,8 @@ private static void CheckAnalysisConsistency(Random random, Analyzer a, bool use
}
reader = new StringReader(text);

long seed = random.Next();
random = new Random((int)seed);
long seed = random.NextInt64();
random = new J2N.Randomizer(seed);
if (random.Next(30) == 7)
{
if (Verbose)
Expand Down Expand Up @@ -1248,7 +1243,7 @@ private static void CheckAnalysisConsistency(Random random, Analyzer a, bool use
if (field != null)
{
reader = new StringReader(text);
random = new Random((int)seed);
random = new J2N.Randomizer(seed);
if (random.Next(30) == 7)
{
if (Verbose)
Expand Down Expand Up @@ -1297,7 +1292,7 @@ internal static int[] ToIntArray(IList<int> list)
/// <summary>Returns a random <see cref="AttributeFactory"/> impl</summary>
public static AttributeFactory NewAttributeFactory(Random random)
{
switch (random.nextInt(2))
switch (random.Next(2))
{
case 0:
return Token.TOKEN_ATTRIBUTE_FACTORY;
Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net.TestFramework/Analysis/CrankyTokenFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public override void End()
public override void Reset()
{
base.Reset();
thingToDo = random.nextInt(100);
thingToDo = random.Next(100);
if (thingToDo == 2 && random.nextBoolean())
{
throw new IOException("Fake IOException from TokenStream.Reset()");
Expand Down
3 changes: 2 additions & 1 deletion src/Lucene.Net.TestFramework/Analysis/MockAnalyzer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Lucene.Net.Support.Threading;
using Lucene.Net.Util;
using Lucene.Net.Util.Automaton;
using RandomizedTesting.Generators;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -72,7 +73,7 @@ public MockAnalyzer(Random random, CharacterRunAutomaton runAutomaton, bool lowe
: base(PER_FIELD_REUSE_STRATEGY)
{
// TODO: this should be solved in a different way; Random should not be shared (!).
this.random = new Random(random.Next());
this.random = new J2N.Randomizer(random.NextInt64());
this.runAutomaton = runAutomaton;
this.lowerCase = lowerCase;
this.filter = filter;
Expand Down
7 changes: 4 additions & 3 deletions src/Lucene.Net.TestFramework/Analysis/MockGraphTokenFilter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Lucene.Net.Analysis.TokenAttributes;
using Lucene.Net.Util;
using RandomizedTesting.Generators;
using System;
using Console = Lucene.Net.Util.SystemConsole;

Expand Down Expand Up @@ -38,13 +39,13 @@ public sealed class MockGraphTokenFilter : LookaheadTokenFilter<LookaheadTokenFi

private readonly ICharTermAttribute termAtt;

private readonly int seed; // LUCENENET specific: changed to int, since .NET random seed is int, not long
private readonly long seed;
private Random random;

public MockGraphTokenFilter(Random random, TokenStream input)
: base(input)
{
seed = random.Next();
seed = random.NextInt64();
termAtt = AddAttribute<ICharTermAttribute>();
}

Expand Down Expand Up @@ -111,7 +112,7 @@ public override void Reset()
// NOTE: must be "deterministically random" because
// baseTokenStreamTestCase pulls tokens twice on the
// same input and asserts they are the same:
this.random = new Random(seed);
this.random = new J2N.Randomizer(seed);
}

protected override void Dispose(bool disposing)
Expand Down
Loading