tests: improved game/chat logs in load tests (now it shows in txt format instead html, example: test_TwoAIPlayGame_Multiple)

This commit is contained in:
Oleg Agafonov 2023-10-11 15:00:33 +04:00
parent fe8b8e1def
commit f653fd4c34
6 changed files with 28 additions and 21 deletions

View file

@ -48,6 +48,10 @@
<groupId>org.unbescape</groupId>
<artifactId>unbescape</artifactId>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
</dependency>
<dependency>
<!-- inner lib for jboss network implementation -->
@ -110,12 +114,6 @@
<artifactId>beansbinding</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<!-- scraping lib to download and parse symbols/images/svg -->
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.14.3</version>
</dependency>
<!-- music player START -->
<dependency>

View file

@ -70,6 +70,10 @@
<groupId>net.java.truevfs</groupId>
<artifactId>truevfs-profile-base</artifactId>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
</dependency>
</dependencies>
<build>

View file

@ -6,6 +6,7 @@ import mage.interfaces.callback.ClientCallback;
import mage.remote.Session;
import mage.view.*;
import org.apache.log4j.Logger;
import org.jsoup.Jsoup;
import java.util.List;
import java.util.UUID;
@ -31,10 +32,12 @@ public class LoadCallbackClient implements CallbackClient {
private GameView gameView;
private final String logsPrefix;
private final Boolean showLogsAsHtml; // original game logs in HTML, but it can be converted to txt for more readable console
public LoadCallbackClient(boolean joinGameChat, String logsPrefix) {
public LoadCallbackClient(boolean joinGameChat, String logsPrefix, Boolean showLogsAsHtml) {
this.joinGameChat = joinGameChat;
this.logsPrefix = logsPrefix;
this.showLogsAsHtml = showLogsAsHtml;
}
@Override
@ -42,7 +45,7 @@ public class LoadCallbackClient implements CallbackClient {
callback.decompressData();
controlCount = 0;
// ignore bloaded logs
// ignore bloated logs
switch (callback.getMethod()) {
case CHATMESSAGE:
case GAME_UPDATE_AND_INFORM:
@ -63,7 +66,8 @@ public class LoadCallbackClient implements CallbackClient {
case CHATMESSAGE: {
ChatMessage message = (ChatMessage) callback.getData();
log.info(getLogStartInfo() + "chat message: " + message.getMessage());
String mes = this.showLogsAsHtml ? message.getMessage() : Jsoup.parse(message.getMessage()).text();
log.info(getLogStartInfo() + "chat message" + (message.getTurnInfo() == null ? "" : " at " + message.getTurnInfo()) + ": " + mes);
break;
}
@ -81,7 +85,7 @@ public class LoadCallbackClient implements CallbackClient {
case GAME_INFORM_PERSONAL: {
GameClientMessage message = (GameClientMessage) callback.getData();
gameView = message.getGameView();
//log.info(getLogStartInfo() + "Inform: " + message.getMessage());
// ignore play priority log
break;
}
@ -99,17 +103,15 @@ public class LoadCallbackClient implements CallbackClient {
case "Select a starting player":
session.sendPlayerUUID(gameId, playerId);
return;
//break;
case "Select a card to discard":
log.info(getLogStartInfo() + "hand size: " + gameView.getHand().size());
SimpleCardView card = gameView.getHand().values().iterator().next();
session.sendPlayerUUID(gameId, card.getId());
return;
//break;
default:
log.error(getLogStartInfo() + "unknown GAME_TARGET message: " + message.toString());
return;
}
break;
}
case GAME_ASK: {
@ -170,8 +172,7 @@ public class LoadCallbackClient implements CallbackClient {
default:
log.error(getLogStartInfo() + "unknown callback: " + callback.getMethod() + ", " + callback.getData().toString());
session.sendPlayerBoolean(gameId, false);
return;
//break;
break;
}
}
@ -188,9 +189,6 @@ public class LoadCallbackClient implements CallbackClient {
private String getLogStartInfo() {
String mes = "";
//throw new IllegalArgumentException("test exception");
PlayerView p = getPlayer();
if (this.gameView != null && p != null && this.gameView.getStep() != null) {
// never calls for client side client, cause it used as game's watcher, not a player

View file

@ -44,6 +44,7 @@ public class LoadTest {
private static final int TEST_PORT = 17171;
private static final String TEST_PROXY_TYPE = "None";
private static final String TEST_USER_NAME_GLOBAL_PREFIX = "t_";
private static final Boolean TEST_SHOW_GAME_LOGS_AS_HTML = false; // html is original format with full data, but can be too bloated
private static final String TEST_AI_GAME_MODE = "Freeform Commander Free For All";
private static final String TEST_AI_DECK_TYPE = "Variant Magic - Freeform Commander";
private static final String TEST_AI_RANDOM_DECK_SETS = "NEO"; // set for random generated decks (empty for all sets usage)
@ -544,7 +545,7 @@ public class LoadTest {
public LoadPlayer(String userPrefix, boolean joinGameChat, String logsPrefix) {
this.userName = TEST_USER_NAME_GLOBAL_PREFIX + userPrefix + "_" + RandomUtil.nextInt(10000);
this.connection = createSimpleConnection(this.userName);
this.client = new SimpleMageClient(joinGameChat, logsPrefix);
this.client = new SimpleMageClient(joinGameChat, logsPrefix, TEST_SHOW_GAME_LOGS_AS_HTML);
this.session = new SessionImpl(this.client);
this.session.connect(this.connection);

View file

@ -23,9 +23,9 @@ public class SimpleMageClient implements MageClient {
private final LoadCallbackClient callbackClient;
public SimpleMageClient(boolean joinGameChat, String logsPrefix) {
public SimpleMageClient(boolean joinGameChat, String logsPrefix, Boolean showLogsAsHtml) {
clientId = UUID.randomUUID();
callbackClient = new LoadCallbackClient(joinGameChat, logsPrefix);
callbackClient = new LoadCallbackClient(joinGameChat, logsPrefix, showLogsAsHtml);
}
@Override

View file

@ -313,6 +313,12 @@
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<!-- scraping lib to download and parse html/symbols/images/svg -->
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.14.3</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>