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

Modernize BWC testing with parameterized tests #13046

Merged
merged 19 commits into from
Jan 31, 2024
Merged

Conversation

s1monw
Copy link
Member

@s1monw s1monw commented Jan 29, 2024

After working on #12829 I was quite surprised about the complexity our BWC have and how ancient the appear compared to the rest of our test suite. I took a step back and tried to modernize the tests to leverage RandomizedRunner Parameterized Tests that allow us to have more structured and hopefully more extendible BWC tests in the future. This change doesn't add any new tests but tries to make the ones we have more structured and support growth down the road.
Basically, every index type got it's own Test class that doesn't require to loop over all the indices in each test. Each test case is run with all versions specified. Several sanity checks are applied in the base class to make individual tests smaller and much easier to read.

@ParametersFactory(argumentFormatting = "Lucene-Version:%1$s; Pattern: %2$s")
public static Iterable<Object[]> testVersionsFactory() {
List<Object[]> params = new ArrayList<>();
// NOCOMMIT: why are we only testing one version here?
Copy link
Member Author

Choose a reason for hiding this comment

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

maybe somebody has an answer to that

}

public void testUpgradeOldSingleSegmentIndexWithAdditions() throws Exception {
// NOCOMMIT we use to have single segment indices but we stopped creating them at some point
Copy link
Member Author

Choose a reason for hiding this comment

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

maybe somebody has an answer to that, this puzzles me as well

Copy link
Member

Choose a reason for hiding this comment

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

I don't know why we stopped! We should start again? But maybe as followon?

Copy link
Contributor

@jpountz jpountz left a comment

Choose a reason for hiding this comment

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

I like the approach. I'm curious of @dweiss' opinion since he's more familiar with the testing framework.

@ParametersFactory(argumentFormatting = "Lucene-Version:%1$s; Pattern: %2$s")
public static Iterable<Object[]> testVersionsFactory() {
List<Object[]> params = new ArrayList<>();
// NOCOMMIT: why are we only testing one version here?
Copy link
Contributor

Choose a reason for hiding this comment

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

I would guess it's because it's more about testing the upgrade logic on empty indexes than about testing the format of old empty indexes.

@dweiss
Copy link
Contributor

dweiss commented Jan 29, 2024

I like it. Whenever there is test repetition that can be driven by data, it should be driven by data.

The only downside to using ParametersFactory is that it's something that is implemented by the randomizedtesting framework (not JUnit itself) and people may be unfamiliar with it - perhaps a comment on the class (or the parameterized constructor) pointing at where the arguments come from would make it easier to grasp how this thing works?

Plain JUnit alternatives do exist but they rely on a different test runner (Parameterized) - you wouldn't be able to extend from LuceneTestCase anymore (and you'd be outside of the randomization context). I don't see any other, more elegant, solutions.

@dweiss
Copy link
Contributor

dweiss commented Jan 29, 2024

Oh, one more problem is that you can't "see" the structure of tests before you actually run them (in an IDE). Don't know how much of an issue this is in practice but it's impossible to solve with JUnit4. Some IDEs may also have problems repeating a particular test if its name contains parameters and their names. But I don't think we should think in terms of IDE support - the final outcome and benefit for maintainability matters more.

Copy link
Member

@mikemccand mikemccand left a comment

Choose a reason for hiding this comment

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

This looks great! Thank you for modernizing our ancient BWC tests @s1monw. I left minor comments. For the // nocommit questions let's make followon issues to address? We should PnP this!

}

public void testUpgradeOldSingleSegmentIndexWithAdditions() throws Exception {
// NOCOMMIT we use to have single segment indices but we stopped creating them at some point
Copy link
Member

Choose a reason for hiding this comment

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

I don't know why we stopped! We should start again? But maybe as followon?

@s1monw
Copy link
Member Author

s1monw commented Jan 30, 2024

We should PnP this!

What on earth means PnP? Mike, check out this search: https://www.google.com/search?q=pnp+acronym wikipedia FTW

Copy link
Contributor

@uschindler uschindler left a comment

Choose a reason for hiding this comment

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

Looks fine to me. Theres only a forbiddenapis problem due to String#formatted.

Replace by String.format(Locale.ROOT, indexPattern, version)

@mikemccand
Copy link
Member

We should PnP this!

What on earth means PnP? Mike, check out this search: https://www.google.com/search?q=pnp+acronym wikipedia FTW

PnP = progress not perfection! Not plug and play, not transistors, heh.

@uschindler
Copy link
Contributor

We should PnP this!

What on earth means PnP? Mike, check out this search: https://www.google.com/search?q=pnp+acronym wikipedia FTW

PnP = progress not perfection! Not plug and play, not transistors, heh.

We all need some drugs sometimes, especially the policeman. 💉💊💊💊

@s1monw
Copy link
Member Author

s1monw commented Jan 30, 2024

@uschindler I need to hear you speaking german to tell, you know that ;)

@s1monw s1monw requested a review from uschindler January 30, 2024 17:09
@s1monw s1monw requested a review from uschindler January 30, 2024 19:44
Copy link
Contributor

@uschindler uschindler left a comment

Choose a reason for hiding this comment

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

Looks fine. All nocommits are todos now.

I think it's ready for a first round. P💊P

P.S.: About the code style I would prefer the list of versions as a Stream.of(...) and converting them to those sets of versions using a stream mapping. Those array declarations look always strange.

@s1monw s1monw merged commit 8d9290c into apache:main Jan 31, 2024
4 checks passed
@s1monw
Copy link
Member Author

s1monw commented Jan 31, 2024

thanks everybody... I will go and backport this to 9.x as well

s1monw added a commit that referenced this pull request Jan 31, 2024
This change modernizes the BWC tests to leverage RandomizedRunners Parameterized Tests that allow us to have more structured and hopefully more extendible BWC tests in the future. This change doesn't add any new tests but tries to make the ones we have more structured and support growth down the road.
Basically, every index type got it's own Test class that doesn't require to loop over all the indices in each test. Each test case is run with all versions specified. Several sanity checks are applied in the base class to make individual tests smaller and much easier to read.

Co-authored-by: Michael McCandless <[email protected]>
Co-authored-by: Adrien Grand <[email protected]>
s1monw added a commit that referenced this pull request Jan 31, 2024
@HoustonPutman
Copy link
Contributor

So I just finished the 8.11.3 release, and had some problems with the back-compat testing code. Obviously the ant/gradle switch and jdk versions meant that I had to do a lot of it manually, but I'm pretty sure the regex matching in the update_backcompat_tests() function in addBackcompatIndexes.py was broken by this commit.

I updated the files myself manually for 8.11.3 (on main and 9x), and I think they are correct (and the tests pass), but I would recommend checking them and re-checking that the python script works with these changes...

s1monw added a commit to s1monw/lucene that referenced this pull request Feb 12, 2024
In apache#13046 several changes broke the addBackcompatIndexes.py script
to properly add and test the unreleased version. This updates the
script to again properly add the new version.

Closes apache#13094
s1monw added a commit that referenced this pull request Feb 14, 2024
…3095)

In #13046 several changes broke the addBackcompatIndexes.py script
to properly add and test the unreleased version. This updates the
script to again properly add the new version.

Closes #13094

Co-authored-by: Dawid Weiss <[email protected]>
s1monw added a commit that referenced this pull request Feb 14, 2024
…3095)

In #13046 several changes broke the addBackcompatIndexes.py script
to properly add and test the unreleased version. This updates the
script to again properly add the new version.

Closes #13094

Co-authored-by: Dawid Weiss <[email protected]>
asfgit pushed a commit that referenced this pull request Feb 20, 2024
…3095)

In #13046 several changes broke the addBackcompatIndexes.py script
to properly add and test the unreleased version. This updates the
script to again properly add the new version.

Closes #13094

Co-authored-by: Dawid Weiss <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants