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

Test/net crash test #786

Merged
merged 3 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

<DefineConstants>$(DefineConstants);FEATURE_ARGITERATOR</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_DICTIONARY_REMOVE_CONTINUEENUMERATION</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_PROCESS_KILL_ENTIREPROCESSTREE</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_STRING_CONCAT_READONLYSPAN</DefineConstants>

</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public RandomizedContext(Test currentTest, Assembly currentTestAssembly, long ra
this.currentTest = currentTest ?? throw new ArgumentNullException(nameof(currentTest));
this.currentTestAssembly = currentTestAssembly ?? throw new ArgumentNullException(nameof(currentTestAssembly));
this.randomSeed = randomSeed;
this.randomSeedAsHex = "0x" + randomSeed.ToHexString();
this.randomSeedAsHex = SeedUtils.FormatSeed(randomSeed);
this.testSeed = testSeed;
}

Expand Down
22 changes: 22 additions & 0 deletions src/Lucene.Net.TestFramework/Support/Util/SeedUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using J2N;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lucene.Net.Util
{
/// <summary>
/// Utilities for parsing and formatting random seeds.
/// </summary>
internal static class SeedUtils
{
/// <summary>
/// Format a single <paramref name="seed"/>.
/// </summary>
// LUCENENET: Our format deviates from the Java randomizedtesting implementation
public static string FormatSeed(long seed)
=> string.Concat("0x", seed.ToHexString());
}
}
20 changes: 13 additions & 7 deletions src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2919,8 +2919,8 @@ public static DirectoryInfo CreateTempDir()
}

/// <summary>
/// Creates an empty, temporary folder with the given name prefix under the
/// system's <see cref="Path.GetTempPath()"/>.
/// Creates an empty, temporary folder with the given name <paramref name="prefix"/> under the
/// system's <see cref="Path.GetTempPath()"/> or if supplied, the <c>tempDir</c> system property.
///
/// <para/>The folder will be automatically removed after the
/// test class completes successfully. The test should close any file handles that would prevent
Expand All @@ -2929,6 +2929,7 @@ public static DirectoryInfo CreateTempDir()
public static DirectoryInfo CreateTempDir(string prefix)
{
//DirectoryInfo @base = BaseTempDirForTestClass();
string @base = SystemProperties.GetProperty("tempDir", System.IO.Path.GetTempPath());

int attempt = 0;
DirectoryInfo f;
Expand All @@ -2942,7 +2943,7 @@ public static DirectoryInfo CreateTempDir(string prefix)
// LUCENENET specific - need to use a random file name instead of a sequential one or two threads may attempt to do
// two operations on a file at the same time.
//f = new DirectoryInfo(Path.Combine(System.IO.Path.GetTempPath(), "LuceneTemp", prefix + "-" + attempt));
f = new DirectoryInfo(Path.Combine(System.IO.Path.GetTempPath(), "LuceneTemp", prefix + "-" + Path.GetFileNameWithoutExtension(Path.GetRandomFileName())));
f = new DirectoryInfo(Path.Combine(@base, "LuceneTemp", prefix + "-" + Path.GetFileNameWithoutExtension(Path.GetRandomFileName())));

try
{
Expand All @@ -2963,19 +2964,20 @@ public static DirectoryInfo CreateTempDir(string prefix)
}

/// <summary>
/// Creates an empty file with the given prefix and suffix under the
/// system's <see cref="Path.GetTempPath()"/>.
/// Creates an empty file with the given <paramref name="prefix"/> and <paramref name="suffix"/> under the
/// system's <see cref="Path.GetTempPath()"/> or if supplied, the <c>tempDir</c> system property.
///
/// <para/>The file will be automatically removed after the
/// test class completes successfully. The test should close any file handles that would prevent
/// the folder from being removed.
/// the file from being removed.
/// </summary>
public static FileInfo CreateTempFile(string prefix, string suffix)
{
//DirectoryInfo @base = BaseTempDirForTestClass();
string @base = SystemProperties.GetProperty("tempDir", System.IO.Path.GetTempPath());

//int attempt = 0;
FileInfo f = FileSupport.CreateTempFile(prefix, suffix, new DirectoryInfo(Path.GetTempPath()));
FileInfo f = FileSupport.CreateTempFile(prefix, suffix, @base);
//do
//{
// if (attempt++ >= TEMP_NAME_RETRY_THRESHOLD)
Expand All @@ -2992,6 +2994,10 @@ public static FileInfo CreateTempFile(string prefix, string suffix)

/// <summary>
/// Creates an empty temporary file.
///
/// <para/>The file will be automatically removed after the
/// test class completes successfully. The test should close any file handles that would prevent
/// the file from being removed.
/// </summary>
/// <seealso cref="CreateTempFile(string, string)"/>
public static FileInfo CreateTempFile()
Expand Down
8 changes: 8 additions & 0 deletions src/Lucene.Net.Tests._I-J/Lucene.Net.Tests._I-J.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@

<Import Project="$(SolutionDir).build/TestReferences.Common.targets" />

<ItemGroup>
<!-- Add the target framework as metadata so our assembly knows which target it is testing -->
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>TargetFramework</_Parameter1>
<_Parameter2>$(TargetFramework)</_Parameter2>
</AssemblyAttribute>
</ItemGroup>

<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
Expand Down
Loading