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: split public MainLoop methods from Engine-management code #73

Merged
merged 5 commits into from
Nov 6, 2021

Conversation

keturn
Copy link
Contributor

@keturn keturn commented Nov 2, 2021

With the last usage of the deprecated ModuleTestingEnvironment superclass removed from Omega, we're free to remove some of the junit-specific things from ModuleTestingHelper's implementation and look at how to split those dozens of methods up into a few classes with separate responsibilities.

This PR puts createHost and related methods in a new class named Engines. It's mostly used for the work that MTEExtension does behind the scenes, but those tests that use createClient to start additional engines may use it directly.

runWhile and related methods are in the class MainLoop. These are the methods that test authors will be interested in. The makeRelevant methods are currently here as well.

ModuleTestingHelper still exists for backwards compatibility, but I'd like to push tests to use the smaller MainLoop interface as much as possible.

Notes for Reviewers

There are a lot of lines, but I think it's okay to assume that all the methods in Engines and MainLoop were moved out of ModuleTestingEnvironment as-is.

MTEExtension does have some changes to allow the extension to provide the new classes to tests.

This should be reviewable/runnable per-commit.

To Do

  • Docs. There's lots of old stuff specific to JUnit 4 that can go away, but we should be sure that the JUnit 5 replacements for those things have matching documentation. javadoc

Cervator
Cervator previously approved these changes Nov 3, 2021
Copy link
Member

@Cervator Cervator left a comment

Choose a reason for hiding this comment

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

Loving the naming and breaking apart of things 👍

long startGameTime = hostTime.getGameTimeInMs();

while (f.get() && !timedOut) {
Thread.yield();
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to add some sort of throttled debug output here that could be used to show the time stats every, say, 10 seconds or so? To help identify when something goes wrong, like a weirdly long timeout, or maybe no progress being made (if there's something to ask for "status")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We certainly have an ongoing need for something to give us more visibility in to what's going on when a test stalls, but that's not in scope for this PR.

* or conversely run until a condition is true via {@link #runUntil(Supplier)} <br>{@code runUntil(()-> false);}
*
* <h2>Specifying Dependencies</h2>
* By default the environment will load only the engine itself. FIXME
Copy link
Member

Choose a reason for hiding this comment

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

Maybe these two FIXMEs can be moved around a bit so there's actual descriptive text behind them?

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've pushed a big update to the javadoc.

Remove references to JUnit 4 methods.
@keturn
Copy link
Contributor Author

keturn commented Nov 5, 2021

@keturn keturn marked this pull request as ready for review November 5, 2021 00:35
@keturn
Copy link
Contributor Author

keturn commented Nov 5, 2021

MTE MainLoop interface

Comment on lines +34 to +77
* Sets up a Terasology environment for use with your {@index JUnit} 5 test.
* <p>
* Supports Terasology's DI as in usual Systems. You can inject Managers via {@link In} annotation, constructor's or
* test's parameters. Also you can inject {@link ModuleTestingHelper} itself.
* Supports Terasology's DI as in usual Systems. You can inject Managers via {@link In} annotation, constructors or
* test parameters. Also you can inject {@link MainLoop} or {@link Engines} to interact with the environment's engine.
* <p>
* Every class annotated with this will create a single {@link ModuleTestingHelper} and use it during execution of
* Example:
* <pre><code>
* import org.junit.jupiter.api.extension.ExtendWith;
* import org.junit.jupiter.api.Test;
* import org.terasology.engine.registry.In;
*
* &#64;{@link org.junit.jupiter.api.extension.ExtendWith}(MTEExtension.class)
* &#64;{@link Dependencies}("MyModule")
* &#64;{@link UseWorldGenerator}("Pathfinding:pathfinder")
* public class ExampleTest {
*
* &#64;In
* EntityManager entityManager;
*
* &#64;In
* {@link MainLoop} mainLoop;
*
* &#64;Test
* public void testSomething() {
* // …
* }
*
* // Injection is also applied to the parameters of individual tests:
* &#64;Test
* public void testSomething({@link Engines} engines, WorldProvider worldProvider) {
* // …
* }
* }
* </code></pre>
* <p>
* You can configure the environment with these additional annotations:
* <dl>
* <dt>{@link Dependencies @Dependencies}</dt>
* <dd>Specify which modules to include in the environment. Put the name of your module under test here.
* Any dependencies these modules declare in <code>module.txt</code> will be pulled in as well.</dd>
* <dt>{@link UseWorldGenerator @UseWorldGenerator}</dt>
* <dd>The URN of the world generator to use. Defaults to {@link org.terasology.moduletestingenvironment.fixtures.DummyWorldGenerator},
* a flat world.</dd>
* </dl>
Copy link
Member

@jdrueckert jdrueckert Nov 5, 2021

Choose a reason for hiding this comment

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

I really like this! 💚
However, I wonder whether this should be added to the README or module docs - not sure whether in addition to or instead of having it here 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's definitely the sort of thing that anyone interested in using MTE will need to know. As for how to organize the docs, I haven't figured that out yet. Neither javadoc nor GitHub-Markdown offer good ways to include source listings like ExampleTest.java.

@keturn keturn merged commit 9db61a9 into develop Nov 6, 2021
@keturn keturn deleted the feat/removeSuperclass branch November 6, 2021 16:14
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.

None yet

3 participants