mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-24 08:12:32 +01:00
Test TickSchedulerThread
This commit is contained in:
parent
ae377307c7
commit
284bf24308
@ -1,12 +1,16 @@
|
||||
package net.minestom.server;
|
||||
|
||||
import net.minestom.server.thread.TickSchedulerThread;
|
||||
import net.minestom.server.timer.TaskSchedule;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class ServerProcessTest {
|
||||
|
||||
@ -27,4 +31,29 @@ public class ServerProcessTest {
|
||||
assertDoesNotThrow(() -> ticker.tick(System.currentTimeMillis()));
|
||||
assertDoesNotThrow(process::stop);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tickScheduling() {
|
||||
var process = MinecraftServer.updateProcess();
|
||||
process.start(new InetSocketAddress("localhost", 25568));
|
||||
AtomicLong time = new AtomicLong();
|
||||
AtomicInteger counter = new AtomicInteger();
|
||||
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
process.scheduler().scheduleTask(() -> {
|
||||
long timeNow = System.currentTimeMillis();
|
||||
long lastTime = time.get();
|
||||
if (lastTime != 0) {
|
||||
long diff = timeNow - lastTime;
|
||||
assertEquals(MinecraftServer.TICK_MS, diff, 5);
|
||||
}
|
||||
time.set(timeNow);
|
||||
if (counter.incrementAndGet() == 10) {
|
||||
process.stop();
|
||||
latch.countDown();
|
||||
}
|
||||
}, TaskSchedule.nextTick(), TaskSchedule.nextTick());
|
||||
new TickSchedulerThread(process).start();
|
||||
assertDoesNotThrow(() -> latch.await());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user