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

Refactor ExtensionsRunner test code out of production source tree #172

Merged
merged 2 commits into from
Oct 10, 2022

Conversation

roulpriya
Copy link
Contributor

Description

Remove ExtensionsRunner constructor which was used only in tests

Issues Resolved

Closes #171

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link
Member

@dbwiddis dbwiddis left a comment

Choose a reason for hiding this comment

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

Looking good so far!

build.gradle Outdated Show resolved Hide resolved
@dbwiddis dbwiddis added the hacktoberfest Global event that encourages people to contribute to open-source. label Oct 9, 2022
@roulpriya roulpriya force-pushed the Issue-171 branch 2 times, most recently from 03c9cac to d75df92 Compare October 10, 2022 08:01
@Override
@BeforeEach
public void setUp() throws Exception {
super.setUp();
this.extensionsRunner = new ExtensionsRunner();
this.extensionsRunner = new ExtensionsRunnerForTest();
this.initialTransportService = extensionsRunner.extensionTransportService;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The constructor of ExtensionRunner creates an instance of TransportService which listens a port in the background.

Tests further use setExtensionTransportService to replace the created instance with a mock to use in testing. The original instance becomes unreachable and our tearDown cannot stop it, which causes the rest of the tests to fail due to the port being already in use. Hence, this hack.

IMO, we should pass TransportService as a constructor parameter and not instantiate inside.

Copy link
Member

Choose a reason for hiding this comment

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

At this point, let's "hack" as needed to get this merged.

I agree with you and have questioned how we've tracked the transport service from some of the initial PRs. I'm not sure putting it in the constructor is the best solution but we do need something better than what we have.

We do have a future requirement to gracefully handle disconnections/reconnections (hot plugin, etc.) and I think handling these will definitely need to be part of that functionality as well.

@roulpriya roulpriya changed the title [WIP] Refactor ExtensionsRunner test code out of production source tree Refactor ExtensionsRunner test code out of production source tree Oct 10, 2022
@roulpriya roulpriya marked this pull request as ready for review October 10, 2022 08:21
@roulpriya roulpriya requested a review from a team October 10, 2022 08:21
Copy link
Member

@dbwiddis dbwiddis left a comment

Choose a reason for hiding this comment

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

Code changes look good! Thank you for your contribution and your patience in dealing with our early-stage code!

Please undo the whitespace changes in build.gradle and add the DCO signoff and I'll approve this.

/**
* Instantiates a new Extensions Runner using the specified extension.
*
* @param extension The settings with which to start the runner.
* @throws IOException if the runner failed to read settings or API.
*/
private ExtensionsRunner(Extension extension) throws IOException {
protected ExtensionsRunner(Extension extension) throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

Note to self/other reviewers: package private would be sufficient for tests if we only want to make ExtensionsRunner extendable for testing. However I think it's reasonable to think any user might wish to create a simple anonymous extension (possibly for their own testing!) so I like using protected here.

src/main/java/org/opensearch/sdk/TransportActions.java Outdated Show resolved Hide resolved
build.gradle Outdated Show resolved Hide resolved
dbwiddis
dbwiddis previously approved these changes Oct 10, 2022
joshpalis
joshpalis previously approved these changes Oct 10, 2022
@dbwiddis dbwiddis dismissed stale reviews from joshpalis and themself via 1cb21b5 October 10, 2022 16:54
@Override
@AfterEach
public void tearDown() throws Exception {
super.tearDown();
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding the tearDown. This will definitely avoid the bind connection error.

@dbwiddis dbwiddis requested a review from joshpalis October 10, 2022 17:02
@@ -0,0 +1,32 @@
package org.opensearch.sdk;
Copy link
Member

Choose a reason for hiding this comment

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

This is great!
It sets up our initial framework for tests going forward.

Copy link
Member

@saratvemulapalli saratvemulapalli left a comment

Choose a reason for hiding this comment

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

Thanks @roulpriya for the changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Global event that encourages people to contribute to open-source.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Refactor ExtensionsRunner test code out of production source tree
5 participants