Skip to content

Commit

Permalink
increased logging for single player test
Browse files Browse the repository at this point in the history
  • Loading branch information
eviltester committed Mar 3, 2024
1 parent 93bf26c commit 5164dbe
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand All @@ -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;
}
}
Expand Down

0 comments on commit 5164dbe

Please sign in to comment.