-
Notifications
You must be signed in to change notification settings - Fork 626
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
Port missing test: TestIndexWriterOnJRECrash #768
Comments
Hello @NightOwl888, I find this is interesting to me I could like to work on this issue. Totally new for FTS, Thanks! |
@Jeevananthan-23 Thanks for volunteering to tackle this. In general we try to port the Java code to .NET as literally as possible while also adhering to standard .NET coding conventions. This unit test will need to be ported a bit less literally then most code since it's written to test that Lucene handles a JRE crash without corrupting the index. While we don't have a JRE in .NET, the analogous thing to test would be to test that the index does not get corrupted if the Lucene thread is terminated at a random interval. This could be accomplished by 1) running the Lucene code on a different thread then the unit test and then terminating the Lucene thread after a random time period or 2) by having the test launch a separate process (which will of course inherently has a thread) that runs Lucene and then killing that process after a random interval. Either approach would probably work fine. |
Hi @Jeevananthan-23. Thanks for volunteering. I don't believe that .NET has a built-in "crash" function that can be executed from the outside of a process like Java does, so we will need to change the approach. My thought is to do something along the lines of:
Of course, if during your research you think you have found another approach that works, you can modify it accordingly. But please use the original |
Actually, after thinking this through a bit more, rather than wiring up a new console app, it makes more sense to simply fire up We don't need to dynamically compile anything because the project this test is in contains the test we need to run. So by the time we run the test there is already a DLL file that we can pass to As for target framework, we have another test where we have done that already.
The above test also has an example of using |
Of course, we still would need a second thread to kill the process, so we can use a similar approach as in Java and just subclass the original test to run and execute that test in the 2nd process. It can use the environment variable that is passing the directory of the index to determine whether it is the original test or the one that is spawned from the original. |
Sounds Challenging to me let me dive deep into it🤿. Thank you for your explanation! |
I think can't stress test internally in my system maybe something is wrong with my code it taking a long time to run 0958023 . Please check the code for the test if possible is there something wrong let me know (Process and ThreadPumper issue). Thanks! |
Looks like it is coming along.
[SetUp]
public override void SetUp()
{
base. Setup();
var tempDir = Environment.GetEnvironmentVariable("tempDir");
if (tempDir is null)
{
TempDir = CreateTempDir("netcrash");
TempDir.Delete();
TempDir.Create();
}
else
{
TempDir = new DirectoryInfo(tempDir);
}
} |
Wait - about passing a temp directory. Let's not do that. I looked at the code and it is passing So, let's NOT do: [SetUp]
public override void SetUp()
{
base. Setup();
var tempDir = Environment.GetEnvironmentVariable("tempDir");
if (tempDir is null)
{
TempDir = CreateTempDir("netcrash");
TempDir.Delete();
TempDir.Create();
}
else
{
TempDir = new DirectoryInfo(tempDir);
}
} And instead pass the system properties. We have renamed them in .NET using a You are missing a bunch of command line arguments to get this to work. This is probably the bare minimum of what we need. ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = "dotnet",
Arguments = String.Join(" ", new[] {
"test", this.GetType().Assembly.Location,
"--framework", GetTargetFramework(),
"--filter", "Name~TestIndexWriterOnJRECrash",
"--logger:\"console;verbosity=normal\"",
"--no-build",
// NOTE: This is special syntax that dotnet test supports to pass .runsettings on the command line
"--", $"RunConfiguration.TargetPlatform={GetTargetPlatform()}" }),
WorkingDirectory = theDirectory,
EnvironmentVariables = {
{ "lucene:tests:seed", RandomizedContext.CurrentContext.RandomSeedAsHex },
{ "lucene:tests:culture", Thread.CurrentThread.CurrentCulture.Name },
{ "tests:crashmode", "true" },
// passing NIGHTLY to this test makes it run for much longer, easier to catch it in the act...
{ "lucene:tests:nightly", "true" }
},
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false
}; And yes, that means we can keep the existing I am not sure how much testing has been done with passing system properties as environment variables has been done, but I know for certain the command line approach works if the above code does not.
Note that I don't know for certain this is the right filter. I got it working before, but I thought I specified |
Let me check further it's consuming my memory a lot because it takes all the test classes so filter variables are not correct. |
@NightOwl888, I submitted the PR and look forward to your feedback. Thanks! |
This test was excluded because we don't have a JRE. But just because we don't have a JRE doesn't mean we don't have to contend with runtime crashes.
The test would need to be refactored to emulate a crash on .NET. The idea is that when a crash occurs, it doesn't corrupt the index.
For anyone curious what it is like to port Java code to .NET, this is a relatively small task that can satisfy your curiosity and will help to ensure Lucene.NET is as stable as it can be.
The text was updated successfully, but these errors were encountered: