From 5164dbe61a71d33975dc669bf3fe288f9556b4f1 Mon Sep 17 00:00:00 2001 From: Alan Richardson Date: Sun, 3 Mar 2024 18:27:53 +0000 Subject: [PATCH] increased logging for single player test --- .../uk/co/compendiumdev/challenge/ChallengeMain.java | 4 +++- .../challenge/challengesrouting/SinglePlayerTest.java | 1 + .../java/uk/co/compendiumdev/sparkstart/Environment.java | 9 ++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/challenger/src/main/java/uk/co/compendiumdev/challenge/ChallengeMain.java b/challenger/src/main/java/uk/co/compendiumdev/challenge/ChallengeMain.java index 4245d51c..0794e1d2 100644 --- a/challenger/src/main/java/uk/co/compendiumdev/challenge/ChallengeMain.java +++ b/challenger/src/main/java/uk/co/compendiumdev/challenge/ChallengeMain.java @@ -16,6 +16,8 @@ public static void main(String[] args) { Logger logger = LoggerFactory.getLogger(ChallengeMain.class); + logger.info("Starting Challenger"); + MainImplementation app = new MainImplementation(); Thingifier thingifier = new ChallengeApiModel().get(); app.registerModel("challengeapi", thingifier); @@ -29,6 +31,7 @@ public static void main(String[] args) { // setup routes required for challenges challenger = new ChallengeRouteHandler(thingifier, app.getApiDefn()); + for (String arg : args) { if (arg.toLowerCase().startsWith("-multiplayer")) { logger.info("Running in multiplayer mode"); @@ -79,7 +82,6 @@ public static void main(String[] args) { challenger.setupGui(app.getGuiManagement()); - if(challenger.isSinglePlayerMode()){ logger.info("Running in Single User Mode"); challenger.getThingifier().ensureCreatedAndPopulatedInstanceDatabaseNamed(Challengers.SINGLE_PLAYER_GUID); diff --git a/challenger/src/test/java/uk/co/compendiumdev/challenge/challengesrouting/SinglePlayerTest.java b/challenger/src/test/java/uk/co/compendiumdev/challenge/challengesrouting/SinglePlayerTest.java index 14103dff..4a9ea937 100644 --- a/challenger/src/test/java/uk/co/compendiumdev/challenge/challengesrouting/SinglePlayerTest.java +++ b/challenger/src/test/java/uk/co/compendiumdev/challenge/challengesrouting/SinglePlayerTest.java @@ -37,6 +37,7 @@ static void stopSinglePlayerServer(){ @Test void canSimulateCreateChallenger() throws InterruptedException { + System.out.println("When running test am i in single player mode? - " + ChallengeMain.getChallenger().isSinglePlayerMode()); final HttpResponseDetails response = http.post("/challenger", ""); Assertions.assertEquals(singlePlayerGuid, diff --git a/challenger/src/test/java/uk/co/compendiumdev/sparkstart/Environment.java b/challenger/src/test/java/uk/co/compendiumdev/sparkstart/Environment.java index f2d5a64a..f3961357 100644 --- a/challenger/src/test/java/uk/co/compendiumdev/sparkstart/Environment.java +++ b/challenger/src/test/java/uk/co/compendiumdev/sparkstart/Environment.java @@ -28,9 +28,11 @@ public static String getBaseUri(boolean isSinglePlayerMode) { // if(true) // return "https://apichallenges.herokuapp.com"; - + logger.info("Checking app running"); // if not running then start the spark if(ChallengeMain.getChallenger()==null || !Port.inUse("localhost", 4567)) { + + logger.info("App not running starting with single player mode == " + isSinglePlayerMode); //start it up Spark.port(4567); String[] args; @@ -44,6 +46,8 @@ public static String getBaseUri(boolean isSinglePlayerMode) { ChallengeMain.main(args); waitTillRunningStatus(true); + + logger.info("App running started with single player mode == " + ChallengeMain.getChallenger().isSinglePlayerMode()); } return "http://localhost:4567"; @@ -55,14 +59,17 @@ public static String getBaseUri(boolean isSinglePlayerMode) { public static void waitTillRunningStatus(final boolean running) { // wait till running int maxtries = 10; + logger.info("Waiting for server to be in state " + running); while (Port.inUse("localhost", 4567) != running) { maxtries--; try { + logger.info(String.format("Waiting for server %d", maxtries)); Thread.sleep(500); } catch (InterruptedException e) { logger.error("Interruption during running check ",e); } if(maxtries<=0){ + logger.info("Max retries in running status finished."); return; } }