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

MTE creates engines more than once for some tests #5038

Closed
Tracked by #5032
keturn opened this issue Jun 1, 2022 · 1 comment · Fixed by #5039
Closed
Tracked by #5032

MTE creates engines more than once for some tests #5038

keturn opened this issue Jun 1, 2022 · 1 comment · Fixed by #5039
Labels
Category: Test/QA Requests, Issues and Changes targeting tests and quality assurance Size: M Medium-sized effort likely requiring some research and work in multiple areas Topic: Stabilization Requests, Issues and Changes related to improving stablity and reducing flakyness Type: Bug Issues reporting and PRs fixing problems

Comments

@keturn
Copy link
Member

keturn commented Jun 1, 2022

On an MTE test that has a @BeforeAll method or that uses field injection with @In, MTE can end up creating more than one set of engines. Something to do with how the postProcessTestInstance method doesn't get a testInstance in its context, but then later when something else does parameter injection on a @BeforeEach or @Test method, it does know the instance, and the way I wrote it stored those under different keys and now there are too many things.

Reproduction test case in #5039.

While addressing this, we might also revisit Terasology/ModuleTestingEnvironment#75
Drop our own @IsolatedMTEExtension stuff and have test authors use Lifecycle.PER_CLASS if they want engines shared between test methods?

@keturn keturn added Type: Bug Issues reporting and PRs fixing problems Size: M Medium-sized effort likely requiring some research and work in multiple areas Topic: Stabilization Requests, Issues and Changes related to improving stablity and reducing flakyness Category: Test/QA Requests, Issues and Changes targeting tests and quality assurance labels Jun 1, 2022
@keturn
Copy link
Member Author

keturn commented Jun 1, 2022

There's some bookkeeping code to catch this off in an experimental branch:

[ MTEExtension.java ]

static class EnginesCleaner implements ExtensionContext.Store.CloseableResource {
@SuppressWarnings("checkstyle:ConstantName")
private static final AtomicInteger engineCount = new AtomicInteger();
protected Engines engines;
final Boolean soleEngineAtCreation;
EnginesCleaner(Set<String> dependencyNames, String worldGeneratorUri, NetworkMode networkMode,
List<Class<? extends EngineSubsystem>> subsystems) {
int currentCount = engineCount.incrementAndGet();
soleEngineAtCreation = currentCount == 1;
logger.debug("About to create new engine. Total: {}", currentCount);
try {
engines = new Engines(dependencyNames, worldGeneratorUri, networkMode, subsystems);
engines.setup();
} catch (Exception e) {
currentCount = engineCount.decrementAndGet();
logger.debug("Engine creation failed. Total: {}", currentCount);
throw e;
}
}
@Override
public void close() {
engines.tearDown();
engines = null;
logger.debug("Tore down an engine. Total: {}", engineCount.decrementAndGet());
}
}

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: M Medium-sized effort likely requiring some research and work in multiple areas Topic: Stabilization Requests, Issues and Changes related to improving stablity and reducing flakyness Type: Bug Issues reporting and PRs fixing problems
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant