-
Notifications
You must be signed in to change notification settings - Fork 1
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
Allow creating a CuratorTestingServerExtension that starts the testing server in the constructor? #239
Comments
* Add two factory methods to CuratorTestingServerExtension that will start the Curator testing server immediately (at construction) instead of during the JUnit lifecycle (i.e. in beforeAll). These are named newStartingImmediately and one will start the testing server on a random port and the other takes a specific port to use. * Before attempting to start the testing server, check that the port is available. Otherwise, when Curator's TestingServer attempts to start, it will never complete. The reason is that TestingServer starts the server in a new Thread and then blocks (without a timeout) until connected. We don't want this behavior in a test extension and instead should fail fast. * Restructure existing test to verify nested test class behavior separate from tests having only top-level tests * Add new test specifically to test the immediate start (necessary since we have to register the CuratorTestingServerExtension with immediate start explicitly) Test restructuring: Split the original CuratorTestingServerExtensionTest test into two separate tests. The first, CuratorTestingServerExtensionTest, contains only top-level tests while the second, CuratorTestingServerExtensionNestedTest, contains both top-level and nested test classes. These two contain essentially the exact same tests, to ensure we are agnostic of how a test is structured. Though as noted in extension's Javadoc, nested test classes will cause us to use multiple testing servers (due to the way the JUnit lifecycle works when using nested test classes). Add CuratorTestingServerExtensionImmediateStartTest to explicitly test the immediate start feature added in this commit. Closes #239
Note that the solution in #242 doesn't add additional constructors and the enum mentioned in the original discussion in this issue. Instead, after initially trying that route (i.e. using the
Doing this avoided a few issues. First, using the enum forced adding multiple new constructors, one that accepted the enum and a second one that accepted the enum and a port in order to cover the various cases. Second, and more importantly, the existing constructors already cover the situation when you want to use the regular JUnit Jupiter extension lifecycle. Having the enum contain a And the code reads better (to me anyway). For example: @RegisterExtension
static final CuratorTestingServerExtension ZK_TEST_SERVER =
CuratorTestingServerExtension.newStartingImmediately();
// or
@RegisterExtension
static final CuratorTestingServerExtension ZK_TEST_SERVER =
CuratorTestingServerExtension.newStartingImmediately(9090); |
…on (#242) * Add two factory methods to CuratorTestingServerExtension that will start the Curator testing server immediately (at construction) instead of during the JUnit lifecycle (i.e. in beforeAll). These are named newStartingImmediately and one will start the testing server on a random port and the other takes a specific port to use. * Before attempting to start the testing server, check that the port is available. Otherwise, when Curator's TestingServer attempts to start, it will never complete. The reason is that TestingServer starts the server in a new Thread and then blocks (without a timeout) until connected. We don't want this behavior in a test extension and instead should fail fast. * Restructure existing test to verify nested test class behavior separate from tests having only top-level tests * Add new test specifically to test the immediate start (necessary since we have to register the CuratorTestingServerExtension with immediate start explicitly) Test restructuring: Split the original CuratorTestingServerExtensionTest test into two separate tests. The first, CuratorTestingServerExtensionTest, contains only top-level tests while the second, CuratorTestingServerExtensionNestedTest, contains both top-level and nested test classes. These two contain essentially the exact same tests, to ensure we are agnostic of how a test is structured. Though as noted in extension's Javadoc, nested test classes will cause us to use multiple testing servers (due to the way the JUnit lifecycle works when using nested test classes). Add CuratorTestingServerExtensionImmediateStartTest to explicitly test the immediate start feature added in this commit. Closes #239
Discussed in #238
Originally posted by sleberknight July 14, 2021
Background
The original (i.e. pre-GitHub) implementation of
CuratorTestingServerExtension
did the following in its constructor:The above is equivalent to:
When we re-implemented this in kiwi-test, we chose to do this in the constructor:
And then in the
beforeAll
we calledtestingServer.start()
. Doing it this way is more correct in the way JUnit Jupiter extensions should behave.However, this caused an issue when testing Dropwizard services using the
DropwizardAppExtension
, specifically because Dropwizard does not follow typical Jupiter extension conventions. It looks something like this when we're using the Dropwizard extension and theCuratorTestingServerExtension
:But when using the kiwiproject extension, the above does not work because there is no way to ensure the Curator
TestingServer
starts before the Dropwizard extension launches the test application. As a result, theApp
classes under test can never connect to a the Curator testing Zookeeper server, so we end up mocking things like leader latches insideApp
by doing something like:This is not ideal, and doesn't test the actual leader latch in the
App
class.To allow us to use the Dropwizard extension and the Curator testing extension, we could add a new constructor in the kiwiproject
CuratorTestingServerExtension
that accepts a second argument that forces the testing server to start immediately, i.e. it would callnew TestingServer(port, true)
.While this is not the "correct" way to do most Jupiter extensions, we don't have a choice in this case if we want to use it with the (nonstandard) Dropwizard extension mechanism. So we might do something like:
where
ServerStart
is perhaps anenum
insideCuratorTestingServerExtension
:Again, while this isn't ideal and not the recommended way, we would no longer need to create the
MockLeaderLatchApp
and mock things out when we're trying to do integration testing.The text was updated successfully, but these errors were encountered: