From 78f94ecb2da37bc235f952003539cd018ed6968f Mon Sep 17 00:00:00 2001 From: Bjarne Koll Date: Tue, 21 Feb 2023 17:18:49 +0100 Subject: [PATCH] Configure mokitor Server mock as stubOnly (#8861) A recent patch moved the internal unit tests to mokito, allowing deep mocking to easily setup a mocked server instance. While this change is useful, the server's Server#getItemFactory methods is one of the hottest paths during unit testing, being called numerous times by material tests. As mokito mocks keep track of each invocation to allow for verifications of invocations down the line, the server mock allocates a huge amount of memory to keep track of all invocations, ultimately leading to an OOM exception. The previous solution solved this by increasing the tests memory to 2 GB, however as of right now simply configuring the server mock as "stubOnly", properly prevents the overflow of invocation records as none of the unit test code relies on invocation verification. --- build.gradle.kts | 2 -- patches/server/Test-changes.patch | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index d3c530db0b..8125f5c25f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -38,8 +38,6 @@ subprojects { exceptionFormat = TestExceptionFormat.FULL events(TestLogEvent.STANDARD_OUT) } - minHeapSize = "2g" - maxHeapSize = "4g" } repositories { diff --git a/patches/server/Test-changes.patch b/patches/server/Test-changes.patch index bb549025b2..a431c6e386 100644 --- a/patches/server/Test-changes.patch +++ b/patches/server/Test-changes.patch @@ -38,6 +38,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.SimplePluginManager; +import org.bukkit.support.AbstractTestingBase; ++import org.mockito.Mockito; + +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.mock; @@ -52,7 +53,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + return; + } + -+ final Server dummyServer = mock(Server.class); ++ final Server dummyServer = mock(Server.class, Mockito.withSettings().stubOnly()); + + final Logger logger = Logger.getLogger(DummyServer.class.getCanonicalName()); + when(dummyServer.getLogger()).thenReturn(logger);