mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-13 02:41:41 +01:00
Add playerSwitch test ensuring that the current thread does not hang
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
95a4d6a1ab
commit
c19d2da2da
@ -5,8 +5,11 @@ import net.minestom.server.api.EnvTest;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.play.JoinGamePacket;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@ -42,4 +45,19 @@ public class EntityInstanceIntegrationTest {
|
||||
assertEquals(1, tracker.collect().size());
|
||||
assertTrue(tracker2.collect().size() > 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void playerSwitch(Env env) {
|
||||
var instance = env.createFlatInstance();
|
||||
var instance2 = env.createFlatInstance();
|
||||
var connection = env.createConnection();
|
||||
var player = connection.connect(instance, new Pos(0, 42, 0)).join();
|
||||
assertEquals(instance, player.getInstance());
|
||||
|
||||
// #join may cause the thread to hang as scheduled for the next tick when initially in a pool
|
||||
Assertions.assertTimeoutPreemptively(Duration.ofSeconds(2), () -> {
|
||||
player.setInstance(instance2).join();
|
||||
});
|
||||
assertEquals(instance2, player.getInstance());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user