tests: improved load tests (added creature stats, improved progress bar)

This commit is contained in:
Oleg Agafonov 2025-02-04 10:23:00 +04:00
parent 7035736a6c
commit f5b901beb4
3 changed files with 52 additions and 11 deletions

View file

@ -33,6 +33,7 @@ public class LoadCallbackClient implements CallbackClient {
private final String logsPrefix;
private final Boolean showLogsAsHtml; // original game logs in HTML, but it can be converted to txt for more readable console
private String globalProgress = ""; // progress [=20, +21, +17], AI game #9: ---
public LoadCallbackClient(boolean joinGameChat, String logsPrefix, Boolean showLogsAsHtml) {
this.joinGameChat = joinGameChat;
@ -40,6 +41,10 @@ public class LoadCallbackClient implements CallbackClient {
this.showLogsAsHtml = showLogsAsHtml;
}
protected void updateGlobalProgress(String globalProgress) {
this.globalProgress = globalProgress;
}
@Override
public void onNewConnection() {
// nothing to do, only one time connection for LoadClient
@ -199,7 +204,7 @@ public class LoadCallbackClient implements CallbackClient {
mes += "T" + this.gameView.getTurn() + "-" + this.gameView.getStep().getIndex() + ", L:" + p.getLibraryCount() + ", H:" + getPlayer().getHandCount() + ": ";
}
return logsPrefix + ": " + mes;
return globalProgress + ", " + logsPrefix + ": " + mes;
}
public void setSession(Session session) {

View file

@ -252,6 +252,7 @@ public class LoadTest {
tasksProgress.update(taskNumber, state == TableState.FINISHED, gameView == null ? 0 : gameView.getTurn());
String globalProgress = tasksProgress.getInfo();
monitor.client.updateGlobalProgress(globalProgress);
if (gameView != null && checkGame != null) {
logger.info(globalProgress + ", " + checkGame.getTableName() + ": ---");
@ -283,12 +284,13 @@ public class LoadTest {
if (Objects.equals(gameView.getActivePlayerId(), p.getPlayerId())) {
activeInfo = " (active)";
}
logger.info(String.format("%s, %s, status: %s - Life=%d; Lib=%d;%s",
logger.info(String.format("%s, %s, status: %s - Life=%d; Lib=%d; CRs=%d%s;",
globalProgress,
checkGame.getTableName(),
p.getName(),
p.getLife(),
p.getLibraryCount(),
p.getBattlefield().values().stream().filter(CardView::isCreature).mapToInt(x -> 1).sum(),
activeInfo
));
});
@ -331,7 +333,7 @@ public class LoadTest {
// play multiple AI games with CLIENT side code (catch every GameView changes from the server)
int singleGameSID = 0; // set sid for same deck games, set 0 for random decks
int gamesAmount = 10; // games per run
int gamesAmount = 5; // games per run
boolean isRunParallel = true; // can generate too much logs in test run, so search server logs for possible errors
ExecutorService executerService;
@ -848,6 +850,22 @@ public class LoadTest {
return finalGameView == null ? 0 : this.finalGameView.getPlayers().get(1).getLife();
}
public int getCreaturesCount1() {
return finalGameView == null ? 0 : this.finalGameView.getPlayers().get(0).getBattlefield().values()
.stream()
.filter(CardView::isCreature)
.mapToInt(x -> 1)
.sum();
}
public int getCreaturesCount2() {
return finalGameView == null ? 0 : this.finalGameView.getPlayers().get(1).getBattlefield().values()
.stream()
.filter(CardView::isCreature)
.mapToInt(x -> 1)
.sum();
}
public int getTurn() {
return finalGameView == null ? 0 : this.finalGameView.getTurn();
}
@ -863,8 +881,8 @@ public class LoadTest {
private static class LoadTestGameResultsList extends HashMap<Integer, LoadTestGameResult> {
private static final String tableFormatHeader = "|%-10s|%-15s|%-20s|%-10s|%-10s|%-15s|%-15s|%-10s|%-20s|%n";
private static final String tableFormatData = "|%-10s|%15s|%20s|%10s|%10s|%15s|%15s|%10s|%20s|%n";
private static final String tableFormatHeader = "|%-10s|%-15s|%-20s|%-10s|%-10s|%-10s|%-10s|%-15s|%-15s|%-10s|%n";
private static final String tableFormatData = "|%-10s|%15s|%20s|%10s|%10s|%10s|%10s|%15s|%15s|%10s|%n";
public LoadTestGameResult createGame(int index, String name, long randomSeed) {
if (this.containsKey(index)) {
@ -882,8 +900,10 @@ public class LoadTest {
"random sid",
"errors",
"turn",
"player 1",
"player 2",
"life p1",
"life p2",
"creatures p1",
"creatures p2",
"time, sec",
"time per turn, sec"
);
@ -901,8 +921,10 @@ public class LoadTest {
String.valueOf(gameResult.randomSeed), // "random sid",
String.valueOf(gameResult.getTotalErrorsCount()), // "errors",
String.valueOf(gameResult.getTurn()), //"turn",
String.valueOf(gameResult.getLife1()), //"player 1",
String.valueOf(gameResult.getLife2()), //"player 2",
String.valueOf(gameResult.getLife1()), //"life p1",
String.valueOf(gameResult.getLife2()), //"life p2",
String.valueOf(gameResult.getCreaturesCount1()), //"creatures p1",
String.valueOf(gameResult.getCreaturesCount2()), //"creatures p2",
String.format("%.3f", (float) gameResult.getDurationMs() / 1000), //"time, sec",
String.format("%.3f", ((float) gameResult.getDurationMs() / 1000) / gameResult.getTurn()) //"per turn, sec"
);
@ -916,8 +938,10 @@ public class LoadTest {
"total, secs: " + String.format("%.3f", (float) this.getTotalDurationMs() / 1000), // "random sid",
String.valueOf(this.getTotalErrorsCount()), // errors
String.valueOf(this.getAvgTurn()), // turn
String.valueOf(this.getAvgLife1()), // player 1
String.valueOf(this.getAvgLife2()), // player 2
String.valueOf(this.getAvgLife1()), // life p1
String.valueOf(this.getAvgLife2()), // life p2
String.valueOf(this.getAvgCreaturesCount1()), // creatures p1
String.valueOf(this.getAvgCreaturesCount2()), // creatures p2
String.valueOf(String.format("%.3f", (float) this.getAvgDurationMs() / 1000)), // time, sec
String.valueOf(String.format("%.3f", (float) this.getAvgDurationPerTurnMs() / 1000)) // time per turn, sec
);
@ -940,6 +964,14 @@ public class LoadTest {
return this.size() == 0 ? 0 : this.values().stream().mapToInt(LoadTestGameResult::getLife2).sum() / this.size();
}
private int getAvgCreaturesCount1() {
return this.size() == 0 ? 0 : this.values().stream().mapToInt(LoadTestGameResult::getCreaturesCount1).sum() / this.size();
}
private int getAvgCreaturesCount2() {
return this.size() == 0 ? 0 : this.values().stream().mapToInt(LoadTestGameResult::getCreaturesCount2).sum() / this.size();
}
private int getTotalDurationMs() {
return this.values().stream().mapToInt(LoadTestGameResult::getDurationMs).sum();
}

View file

@ -28,6 +28,10 @@ public class SimpleMageClient implements MageClient {
callbackClient = new LoadCallbackClient(joinGameChat, logsPrefix, showLogsAsHtml);
}
protected void updateGlobalProgress(String globalProgress) {
callbackClient.updateGlobalProgress(globalProgress);
}
@Override
public MageVersion getVersion() {
return version;