mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2025-01-01 14:07:56 +01:00
Fix race error in bulk update integration test
This commit is contained in:
parent
71416baff2
commit
f12d3cd8ba
@ -1086,7 +1086,7 @@ public class CommandsIntegrationTest {
|
|||||||
|
|
||||||
.givenHasPermissions("luckperms.bulkupdate")
|
.givenHasPermissions("luckperms.bulkupdate")
|
||||||
.whenRunCommand("bulkupdate all update permission group.mod \"permission == group.moderator\"")
|
.whenRunCommand("bulkupdate all update permission group.mod \"permission == group.moderator\"")
|
||||||
.thenExpect("[LP] Running bulk update.");
|
.thenExpectStartsWith("[LP] Running bulk update.");
|
||||||
|
|
||||||
assertTrue(completed.await(15, TimeUnit.SECONDS), "operation did not complete in the allotted time");
|
assertTrue(completed.await(15, TimeUnit.SECONDS), "operation did not complete in the allotted time");
|
||||||
|
|
||||||
|
@ -45,8 +45,10 @@ import java.util.Set;
|
|||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility for testing LuckPerms commands with BDD-like given/when/then assertions.
|
* Utility for testing LuckPerms commands with BDD-like given/when/then assertions.
|
||||||
@ -155,10 +157,7 @@ public final class CommandTester implements Consumer<Component>, Function<String
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
public CommandTester thenExpect(String expected) {
|
public CommandTester thenExpect(String expected) {
|
||||||
String actual = this.renderBuffer().stream()
|
String actual = this.renderBuffer();
|
||||||
.map(String::trim)
|
|
||||||
.collect(Collectors.joining("\n"));
|
|
||||||
|
|
||||||
assertEquals(expected.trim(), actual.trim());
|
assertEquals(expected.trim(), actual.trim());
|
||||||
|
|
||||||
if (this.permissions != null) {
|
if (this.permissions != null) {
|
||||||
@ -168,6 +167,23 @@ public final class CommandTester implements Consumer<Component>, Function<String
|
|||||||
return this.clearMessageBuffer();
|
return this.clearMessageBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the current contents of the message buffer starts with the given input string.
|
||||||
|
*
|
||||||
|
* @param expected the expected contents
|
||||||
|
* @return this
|
||||||
|
*/
|
||||||
|
public CommandTester thenExpectStartsWith(String expected) {
|
||||||
|
String actual = this.renderBuffer();
|
||||||
|
assertTrue(actual.trim().startsWith(expected.trim()), "expected '" + actual + "' to start with '" + expected + "'");
|
||||||
|
|
||||||
|
if (this.permissions != null) {
|
||||||
|
assertEquals(this.checkedPermissions, this.permissions.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.clearMessageBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the message buffer.
|
* Clears the message buffer.
|
||||||
*
|
*
|
||||||
@ -180,14 +196,21 @@ public final class CommandTester implements Consumer<Component>, Function<String
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders the contents of the message buffer.
|
* Renders the contents of the message buffer as a stream of lines.
|
||||||
*
|
*
|
||||||
* @return rendered copy of the buffer
|
* @return rendered copy of the buffer
|
||||||
*/
|
*/
|
||||||
public List<String> renderBuffer() {
|
public Stream<String> renderBufferStream() {
|
||||||
return this.messageBuffer.stream()
|
return this.messageBuffer.stream().map(component -> PlainTextComponentSerializer.plainText().serialize(component));
|
||||||
.map(component -> PlainTextComponentSerializer.plainText().serialize(component))
|
}
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
/**
|
||||||
|
* Renders the contents of the message buffer as a joined string.
|
||||||
|
*
|
||||||
|
* @return rendered copy of the buffer
|
||||||
|
*/
|
||||||
|
public String renderBuffer() {
|
||||||
|
return this.renderBufferStream().map(String::trim).collect(Collectors.joining("\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -206,7 +229,7 @@ public final class CommandTester implements Consumer<Component>, Function<String
|
|||||||
System.out.printf(".givenHasPermissions(%s)%n", checkedPermissions);
|
System.out.printf(".givenHasPermissions(%s)%n", checkedPermissions);
|
||||||
System.out.printf(".whenRunCommand(\"%s\")%n", cmd);
|
System.out.printf(".whenRunCommand(\"%s\")%n", cmd);
|
||||||
|
|
||||||
List<String> render = this.renderBuffer();
|
List<String> render = this.renderBufferStream().toList();
|
||||||
if (render.size() == 1) {
|
if (render.size() == 1) {
|
||||||
System.out.printf(".thenExpect(\"%s\")%n", render.get(0));
|
System.out.printf(".thenExpect(\"%s\")%n", render.get(0));
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user