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

Run tests on .NET 9, #1019 #1052

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

Conversation

paulirwin
Copy link
Contributor

@paulirwin paulirwin commented Nov 28, 2024

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a change, please open an issue to discuss the change or find an existing issue.

Run tests on .NET 9

Fixes #1019
Fixes #1037

Description

Adds .NET 9 to the test suite. As part of this, added assertions around Stream.Read calls where the result was not checked.

The behavior of the IL conv.i8 opcode (used in Expressions.JS) has changed in .NET 9 (at least for x64). It now behaves like Arm64. Instead of having to keep up with which matrix of frameworks and architectures produces what is effectively a meaningless value (division by zero then converting to long is undefined behavior in the CLR), this changes the assertion to allow for either value, regardless of framework/architecture.

Due to the netstandard1.x warning, this PR also fixes #1037 and suppresses the warning for the code analysis projects on netstandard1.3 that must support Visual Studio 2017.

@paulirwin paulirwin added the notes:new-feature A new feature label Nov 28, 2024
@paulirwin paulirwin marked this pull request as draft November 28, 2024 01:09
@paulirwin
Copy link
Contributor Author

paulirwin commented Nov 28, 2024

Running tests on ADO now; need to look into GitHub test failures and add LUCENENET comments for ReadExactly usage. Converted to draft.

@paulirwin
Copy link
Contributor Author

This passes on ADO and GitHub fully now; ready for review. See updated PR description for an explanation on the Expressions.JS test change.

@paulirwin paulirwin marked this pull request as ready for review November 28, 2024 04:45
src/Lucene.Net/Support/StreamExtensions.cs Outdated Show resolved Hide resolved
src/Lucene.Net.Tests.Replicator/IndexInputStreamTest.cs Outdated Show resolved Hide resolved
azure-pipelines.yml Outdated Show resolved Hide resolved
azure-pipelines.yml Show resolved Hide resolved
.build/azure-templates/run-tests-on-os.yml Outdated Show resolved Hide resolved
@paulirwin paulirwin changed the title Run tests on .NET 9 and add Stream.ReadExactly polyfill, #1019 Run tests on .NET 9, #1019 Dec 2, 2024
@in.Read(inBytes, offset, inBytes.Length - offset);

var numRead = @in.Read(inBytes, offset, inBytes.Length - offset); // LUCENENET specific - asserting that we read the entire buffer
assertEquals(inBytes.Length - offset, numRead);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are already doing a length check on line 165, so there is no need to do it again here.

ReadExactly() can potentially throw an exception if the length passed in is larger than the number of bytes left to read. This means that any test that does not assert the length prior to the call to ReadExactly() could potentially throw a less useful exception, which is why I pointed it out in that other example (although, after reviewing again, I see that the length of one side is used to set the length of the other, so the assert would never fail). ReadExactly() could work in this case because the prior length check is being done, thus heading off the exception.

That being said, ReadExactly() doesn't seem all that useful unless there are production cases where the exception would be helpful. In tests, it would be more practical to suppress the warning to keep this in sync with upstream.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to please reconsider leaving this as-is as of my latest changes rather than suppressing the warning.

  1. It adds another assertion that makes our tests more robust than upstream.
  2. I've already added a LUCENENET-specific comment to it explaining the divergence, as is our standard practice.
  3. It resolves the warning, in IMO a cleaner way than a suppression would.
  4. It demonstrates best practices of reviewing the result of the Read call to ensure you didn't hit an end of stream, even if semi-redundantly asserted below.
  5. It achieves your prior concern about not having an exception being thrown by ReadExactly.

stream.Read(readBuffer, 0, readBytes);
{
var numRead = stream.Read(readBuffer, 0, readBytes); // LUCENENET specific - asserting that we read the entire buffer
Assert.AreEqual(readBytes, numRead);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment in IndexAndTaxonomyRevisionTest.

@in.Read(inBytes, offset, inBytes.Length - offset);

var numRead = @in.Read(inBytes, offset, inBytes.Length - offset); // LUCENENET specific - asserting that we read the entire buffer
assertEquals(inBytes.Length - offset, numRead);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment in IndexAndTaxonomyRevisionTest.

@@ -231,7 +231,9 @@ private void AssertFilesIdentical(FileInfo golden, FileInfo sorted)
using Stream is2 = sorted.Open(FileMode.Open, FileAccess.Read, FileShare.Delete);
while ((len = is1.Read(buf1, 0, buf1.Length)) > 0)
{
is2.Read(buf2, 0, len);
var numRead = is2.Read(buf2, 0, len); // LUCENENET specific - asserting that we read the entire buffer
Assert.AreEqual(len, numRead);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment in IndexAndTaxonomyRevisionTest.

@@ -254,7 +256,9 @@ private void AssertFilesIdentical(FileStream golden, FileStream sorted)
Stream is2 = sorted;
while ((len = is1.Read(buf1, 0, buf1.Length)) > 0)
{
is2.Read(buf2, 0, len);
var numRead = is2.Read(buf2, 0, len); // LUCENENET specific - asserting that we read the entire buffer
Assert.AreEqual(len, numRead);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment in IndexAndTaxonomyRevisionTest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
notes:new-feature A new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suppress netstandard1.x warning for Lucene.Net.CodeAnalysis projects Run tests on .NET 9
2 participants