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

Convert main integration tests into reusable backbox tests #590

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dimas-b
Copy link
Contributor

@dimas-b dimas-b commented Dec 26, 2024

  • Introduce new module: integration-tests to contain the test code for backbox integration tests

  • Refactors existing main integration tests to avoid relying on Dropwizard internals.

  • Add new test extension for managing the test environment with custom server managers discovered via ServiceLoader

  • Use Dropwizard test extentions for the reference implementation of PolarisServerManager. Custom server builds can provide their own environment-specific implementations.

  • Add helper classes for REST API (Management and Catalog)

  • Run reusable tests by extending them in the DW module. Using test suites is also possible, but it only uses one gradle test worker, so test parallelism is reduced. At the same time running tests in parallel withing the same JVM using JUnit5 threads currently leads to errors.


This PR is meant to be the first step towards #524. Subsequent PRs can certainly enhance the testing framework more.

gradle/libs.versions.toml Outdated Show resolved Hide resolved

@Override
public URI baseUri() {
return URI.create(String.format("http://localhost:%d", ext.getLocalPort()));
Copy link
Contributor

Choose a reason for hiding this comment

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

The old TestEnv extension could modify this to hit a remote Polaris server afaict.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thinking was that remote cases would have their own Server Manager impl.

The old TestEnvironmentExtension is too intertwined with existing whitebox DW extensions... I though we'd have a totally new interface and gradually migrate TestEnvironmentExtension use cases to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To clarify: if a remote server is available outside the JUnit5 lifecycle, one can simply make an Server Manager impl. that returned a pre-configured URI and Realm, and then use a JUnit5 "suite" to execute tests from the new test module.


@Override
public ClientCredentials adminCredentials() {
return new ClientCredentials("test-admin", "test-secret");
Copy link
Contributor

Choose a reason for hiding this comment

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

The old TestEnv extension used to append a "test ID" to the generated credentials afaict.

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'm not sure that the purpose of that append was, TBH 😅 I believe having one admin user per realm (as in this case) is sufficient.

Currently, there's only one realm for Server Manager instance, so other implementations can chose to use unique admin user names, if they prefer.


AuthToken adminToken();

ClientCredentials adminCredentials();
Copy link
Contributor

Choose a reason for hiding this comment

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

Where has the Snowman user gone?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Into the Nothing. The Server Manager provides "root" (admin) credentials. Tests create extra principals when they need to.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am fine with that, although my impression was that the snowman user was introduced precisely to avoid using the root user for all admin tasks. Let's wait and see what @andrew4699 says.

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 moved the work done by the SnowmanCredentialsExtension into specific test classes... hopefully maintaining the same functionality as before (the "snowman" principals used to be created using "admin" tokens too). Those can be found by searching for "snowman" in Principal names in the new test code. I believe explicit principal manipulation by test code is easier to follow and maintain than if it is done by a test extension.

The principal and role manipulation logic moved to the methods in the new ManagementApi class.

* Introduce new module: `integration-tests` to contain the test
  code for backbox integration tests

* Refactors existing main integration tests to avoid relying on
  Dropwizard internals.

* Add new test extension for managing the test environment with
  custom server managers discovered via `ServiceLoader`

* Use Dropwizard test extentions for the reference implementation
  of `PolarisServerManager`. Custom server builds can provide
  their own environment-specific implementations.

* Add helper classes for REST API (Management and Catalog)

* Run reusable tests by extending them in the DW module.
  Using test suites is also possible, but it only uses one
  gradle test worker, so test parallelism is reduced. At the
  same time running tests in parallel withing the same JVM using
  JUnit5 threads currently leads to errors.
@adutra
Copy link
Contributor

adutra commented Dec 31, 2024

I noticed that 3 other tests use the Dropwizard extension and could be considered as "integration" tests:

  • FileIOIntegrationTest
  • RateLimiterFilterTest
  • TimedApplicationEventListenerTest

We could create "black-box" versions of those while still keeping the "white-box" ones around, wdyt?

.stream()
.collect(
Collectors.toMap(PolarisFeatureConfig::name, PolarisFeatureConfig::value));
return new Env(manager.realm(), manager.startServer(featureConfig));
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm struggling to adapt this to Quarkus. In a Quarkus test (integration or not), the application will be running already when the extension is executed, and it's not possible to change the feature configs at that moment. The only way to change the application config is through a QuarkusTestProfile afaik. I don't think we can use a QuarkusTestResourceLifecycleManager to launch the application itself on demand; that's intended for dependent resources like databases etc. I think the @PolarisFeatureConfig annotation would eventually go away completely with Quarkus.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me see if we this can be refactored to fit Quarkus better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On a closer look at the test that use @PolarisFeatureConfig I tend to think that those tests are an overkill to have at the integration test level. The test variations merely check how configuration keys are resolved between catalog properties, server config and default values. I believe that part can be done by a unit test.

I'll try and refactor the blackbox tests to rely only on default config settings.

@dimas-b
Copy link
Contributor Author

dimas-b commented Dec 31, 2024

FileIOIntegrationTest is not really a blackbox test. It tweaks the internals of CDI in DW. I'm not even sure why it needs a DropwizardAppExtension. I think it can be converted to a proper unit test.

RateLimiterFilterTest could indeed be converted to a blackbox test. I did not do this initially because I thought that the test would become non-deterministic in the presence of other tests if the server is shared. Do you think it would be valuable as a blackbox test?

TimedApplicationEventListenerTest makes assertions that assume exclusive access to the server, so I'm not sure it would be valuable as a blackbox text when the server is shared.

@dimas-b
Copy link
Contributor Author

dimas-b commented Dec 31, 2024

FileIOIntegrationTest refactoring: #598

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants