more threading work
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2024-08-23 09:38:12 -04:00
parent 5563b4366f
commit 82027a20cb
8 changed files with 49 additions and 48 deletions

View File

@ -3,8 +3,10 @@ package electrosphere.engine;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import electrosphere.engine.loadingthreads.LoadingThread;
import electrosphere.util.CodeUtils;
/**
* Manages all running threads
@ -35,7 +37,6 @@ public class ThreadManager {
List<Thread> threadsToRemove = new LinkedList<Thread>();
for(LoadingThread thread : loadingThreads){
if(thread.isDone()){
System.out.println("Collect loading thread of type " + thread.getType());
threadsToRemove.add(thread);
}
}
@ -93,8 +94,15 @@ public class ThreadManager {
//
//interrupt all threads
for(Thread thread : activeThreads){
thread.interrupt();
for(int i = 0; i < 3; i++){
for(Thread thread : activeThreads){
thread.interrupt();
}
try {
TimeUnit.MILLISECONDS.sleep(3);
} catch (InterruptedException e) {
CodeUtils.todo(e, "Handle failing to sleep while interrupting all other threads");
}
}
threadLock.release();
}

View File

@ -75,7 +75,6 @@ public class LoadingThread extends Thread {
@Override
public void run(){
System.out.println("Start loading thread of type " + this.threadType);
switch(threadType){
case TITLE_MENU: {

View File

@ -7,6 +7,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Set;
import org.joml.Vector3d;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import annotations.IntegrationTest;
import electrosphere.engine.Globals;
@ -24,7 +27,9 @@ import testutils.TestEngineUtils;
/**
* Tests for client side equip state
*/
public class ClientEquipStateTests extends EntityTestTemplate {
@ExtendWith(EntityTestTemplate.class)
@Execution(ExecutionMode.SAME_THREAD)
public class ClientEquipStateTests {
/**

View File

@ -7,6 +7,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
import org.joml.Vector3d;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import annotations.IntegrationTest;
import electrosphere.engine.Globals;
@ -22,7 +25,9 @@ import testutils.TestEngineUtils;
/**
* Server equip state tests
*/
public class ServerEquipStateTests extends EntityTestTemplate {
@ExtendWith(EntityTestTemplate.class)
@Execution(ExecutionMode.SAME_THREAD)
public class ServerEquipStateTests {
/**
* Try equipping an item

View File

@ -1,5 +1,7 @@
package electrosphere.renderer.ui.elements;
import org.junit.jupiter.api.extension.ExtendWith;
import annotations.IntegrationTest;
import electrosphere.menu.WindowUtils;
import electrosphere.menu.mainmenu.MenuGeneratorsUITesting;
@ -9,6 +11,7 @@ import testutils.TestEngineUtils;
/**
* Tests for the window class
*/
@ExtendWith(RenderingTestTemplate.class)
public class WindowTest extends RenderingTestTemplate {
/**

View File

@ -4,7 +4,6 @@ import annotations.IntegrationSetup;
import annotations.IntegrationTest;
import electrosphere.engine.Globals;
import electrosphere.engine.profiler.Profiler;
import electrosphere.logger.LoggerInterface;
import electrosphere.net.NetUtils;
public class StartupTest {

View File

@ -1,10 +1,8 @@
package template;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.extension.ExtensionContext;
import annotations.IntegrationSetup;
import annotations.IntegrationTeardown;
import electrosphere.engine.Main;
import testutils.EngineInit;
import testutils.TestEngineUtils;
@ -12,14 +10,10 @@ import testutils.TestEngineUtils;
/**
* Template for writing tests that do stuff with entities in a proper scene
*/
public abstract class EntityTestTemplate extends RenderingTestTemplate {
public class EntityTestTemplate extends RenderingTestTemplate {
/**
* Starts up the entity scene
*/
@IntegrationSetup
@Override
public void initEngine(){
public void beforeEach(ExtensionContext context) throws Exception {
//init engine
TestEngineUtils.initGraphicalEngine();
@ -27,12 +21,4 @@ public abstract class EntityTestTemplate extends RenderingTestTemplate {
EngineInit.setupConnectedTestScene();
}
/**
* Shuts down the engine
*/
@IntegrationTeardown
public void closeEngine(){
Main.shutdown();
}
}

View File

@ -3,39 +3,21 @@ package template;
import java.io.File;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import annotations.IntegrationSetup;
import annotations.IntegrationTeardown;
import electrosphere.engine.Globals;
import electrosphere.engine.Main;
import testutils.TestEngineUtils;
import testutils.TestRenderingUtils;
@Tag("Graphical")
@Tag("integration")
@Tag("graphical")
/**
* A test class that involves testing renders
*/
public abstract class RenderingTestTemplate {
/**
* Initializes the engine
*/
@IntegrationSetup
public void initEngine(){
Globals.WINDOW_DECORATED = false;
Globals.WINDOW_FULLSCREEN = true;
Globals.WINDOW_WIDTH = 1920;
Globals.WINDOW_HEIGHT = 1080;
TestEngineUtils.initGraphicalEngine();
}
/**
* Shuts down the engine
*/
@IntegrationTeardown
public void closeEngine(){
Main.shutdown();
}
public class RenderingTestTemplate implements BeforeEachCallback, AfterEachCallback {
/**
* Checks the most recent render versus an existing image
@ -57,4 +39,18 @@ public abstract class RenderingTestTemplate {
});
}
@Override
public void afterEach(ExtensionContext context) throws Exception {
Globals.WINDOW_DECORATED = false;
Globals.WINDOW_FULLSCREEN = true;
Globals.WINDOW_WIDTH = 1920;
Globals.WINDOW_HEIGHT = 1080;
TestEngineUtils.initGraphicalEngine();
}
@Override
public void beforeEach(ExtensionContext context) throws Exception {
Main.shutdown();
}
}