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

test(MTE): allow a test to add its own EngineSubsystem #5044

Merged
merged 3 commits into from
Jun 12, 2022

Conversation

keturn
Copy link
Member

@keturn keturn commented Jun 11, 2022

  • Main feature: Allows a test to specify @IntegrationEnvironment(subsystem=SomeEngineSubsystem.class), giving the author more control during engine initialization and much more power to shoot themselves in the foot.
  • Moves some bits of configuration out of integrationenvironment.Engines and in to an IntegrationEnvironmentSubsystem. This makes it easier to guess when that code will be run (compared to usual non-MTE code), and makes it easier to override if needed.

Review Hints

IntegrationEnvironmentSubsystem.registerCurrentDirectoryIfModule is a direct move of a method formerly in integrationenvironent.Engines.

How to test

This is an MTE-only change, so there's no player-visible impact. You could use CustomSubsystemTest as an example to start from if you want to experiment with it yourself.

@keturn keturn mentioned this pull request Jun 11, 2022
6 tasks
@keturn keturn added Category: Test/QA Requests, Issues and Changes targeting tests and quality assurance Size: S Small effort likely only affecting a single area and requiring little to no research labels Jun 11, 2022
/**
* Do not add an extra subsystem to the integration environment.
* <p>
* [Odd marker interface because annotation fields cannot default to null.]
Copy link
Member

Choose a reason for hiding this comment

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

❓ Can/should one use Optional? Can there be more than subsystem added (in principle, not necessarily in practice)? If so, this could also be a list.

In any case, having this marker interface in engine-tests is just fine, as it is definitely understandable and we should probably not spent too much time and effort on this (now).

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think we can. The list of types allowed to annotations is quite limited.

Comment on lines +18 to +39
/**
* The network mode the host engine starts with.
* <p>
* See {@link NetworkMode} for details on the options.
* <p>
* Some modes automatically include a {@link LocalPlayer}.
* <p>
* If you want to simulate multiple players with
* {@link org.terasology.engine.integrationenvironment.Engines#createClient Engines.createClient},
* you will need a mode with a {@linkplain NetworkMode#isServer() server}.
*/
NetworkMode networkMode() default NetworkMode.NONE;

/**
* Add an additional subsystem to the engine.
* <p>
* A new instance will be included in the engine's subsystems when it is created.
* <p>
* Implementing {@link EngineSubsystem#initialise} gives you the opportunity to
* make changes to the configuration <em>before</em> it would otherwise be available.
*/
Class<? extends EngineSubsystem> subsystem() default NO_SUBSYSTEM.class;
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 the doc strings!

@@ -195,16 +194,31 @@ TerasologyEngine createHeadlessEngine() throws IOException {
TerasologyEngine createHeadedEngine() throws IOException {
EngineSubsystem audio = new LwjglAudio();
TerasologyEngineBuilder terasologyEngineBuilder = new TerasologyEngineBuilder()
.add(new WithUnittestModule())
.add(new IntegrationEnvironmentSubsystem())
.add(audio)
Copy link
Member

Choose a reason for hiding this comment

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

❓ for the sake of consistency, can we just inline the creation of audio here as well, or do we need it explicitly somewhere else?

Suggested change
.add(audio)
.add(new LwjglAudio())

@@ -195,16 +194,31 @@ TerasologyEngine createHeadlessEngine() throws IOException {
TerasologyEngine createHeadedEngine() throws IOException {
EngineSubsystem audio = new LwjglAudio();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
EngineSubsystem audio = new LwjglAudio();

@keturn keturn merged commit 558c841 into develop Jun 12, 2022
@keturn keturn deleted the test/mteSubsystem branch June 12, 2022 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Test/QA Requests, Issues and Changes targeting tests and quality assurance Size: S Small effort likely only affecting a single area and requiring little to no research
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants