Parallelize tests properly

This commit is contained in:
Octavia Togami 2021-06-11 14:12:09 -07:00
parent bf78034628
commit 4d6c1973f3
No known key found for this signature in database
GPG Key ID: CC364524D1983C99
4 changed files with 38 additions and 2 deletions

View File

@ -25,8 +25,10 @@
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extension.platform.Preference;
import com.sk89q.worldedit.util.test.ResourceLockKeys;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.parallel.ResourceLock;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -39,6 +41,7 @@
/**
* Common setup code for expression tests.
*/
@ResourceLock(ResourceLockKeys.WORLDEDIT_PLATFORM)
class BaseExpressionTest {
static double readSlot(Expression expr, String name) {

View File

@ -28,6 +28,7 @@
import com.sk89q.worldedit.extension.platform.Preference;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.Registry;
import com.sk89q.worldedit.util.test.ResourceLockKeys;
import com.sk89q.worldedit.util.test.VariedVectorGenerator;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockType;
@ -40,6 +41,9 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.junit.jupiter.api.parallel.ResourceLock;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@ -67,6 +71,8 @@
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
@Execution(ExecutionMode.CONCURRENT)
@ResourceLock(ResourceLockKeys.WORLDEDIT_PLATFORM)
@DisplayName("An ordered block map")
class BlockMapTest {
@ -468,7 +474,7 @@ void returnsDefaultFromGetOrDefaultWrongKey() {
@Test
@DisplayName("calls the forEach action once")
void neverCallsForEachAction() {
generator.makeVectorsStream().forEach(vec -> {
generator.makeVectorsStream().sequential().forEach(vec -> {
try (AutoCloseable ignored = MockitoAnnotations.openMocks(this)) {
BlockMap<BaseBlock> map = BlockMap.createForBaseBlock();
map.put(vec, air);

View File

@ -0,0 +1,27 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.util.test;
public class ResourceLockKeys {
public static final String WORLDEDIT_PLATFORM = "WORLDEDIT_PLATFORM";
private ResourceLockKeys() {
}
}

View File

@ -2,4 +2,4 @@ junit.jupiter.execution.parallel.enabled=true
junit.jupiter.execution.parallel.mode.default=concurrent
junit.jupiter.execution.parallel.mode.classes.default=same_thread
junit.jupiter.execution.parallel.config.strategy=dynamic
junit.jupiter.execution.parallel.config.dynamic.factor=1
junit.jupiter.execution.parallel.config.dynamic.factor=4