Tests: improved load test (added connection errors processing, fixed too long generated usernames, related to #10154);

This commit is contained in:
Oleg Agafonov 2023-04-05 18:43:16 +04:00
parent 4f583a853e
commit a9f1e15168
4 changed files with 26 additions and 7 deletions

View file

@ -602,6 +602,14 @@ public class SessionImpl implements Session {
return callbackClient.isConnected(); return callbackClient.isConnected();
} }
@Override
public Boolean isServerReady() {
// Is server works fine, possible use cases:
// - client connected by network, but can't process register/login process due errors like wrong username
// - client connected to broken server that has a wrong config or broken/miss libraries
return isConnected() && serverState != null && serverState.getGameTypes().size() > 0;
}
@Override @Override
public PlayerType[] getPlayerTypes() { public PlayerType[] getPlayerTypes() {
return serverState.getPlayerTypes(); return serverState.getPlayerTypes();

View file

@ -29,4 +29,6 @@ public interface ServerState {
String getVersionInfo(); String getVersionInfo();
Boolean isServerReady();
} }

View file

@ -7,6 +7,7 @@ import mage.remote.Session;
import mage.view.*; import mage.view.*;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import java.util.List;
import java.util.UUID; import java.util.UUID;
/** /**
@ -81,6 +82,12 @@ public class LoadCallbackClient implements CallbackClient {
break; break;
} }
case SHOW_USERMESSAGE: {
List<String> messageData = (List<String>) callback.getData();
log.info("Warning message: " + String.join(" - ", messageData));
break;
}
case GAME_TARGET: { case GAME_TARGET: {
GameClientMessage message = (GameClientMessage) callback.getData(); GameClientMessage message = (GameClientMessage) callback.getData();
this.gameView = message.getGameView(); this.gameView = message.getGameView();

View file

@ -43,7 +43,7 @@ public class LoadTest {
private static final String TEST_SERVER = "localhost"; private static final String TEST_SERVER = "localhost";
private static final int TEST_PORT = 17171; private static final int TEST_PORT = 17171;
private static final String TEST_PROXY_TYPE = "None"; private static final String TEST_PROXY_TYPE = "None";
private static final String TEST_USER_NAME = "user"; private static final String TEST_USER_NAME_GLOBAL_PREFIX = "t_";
private static final String TEST_AI_GAME_MODE = "Freeform Commander Free For All"; 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_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) private static final String TEST_AI_RANDOM_DECK_SETS = "NEO"; // set for random generated decks (empty for all sets usage)
@ -127,7 +127,7 @@ public class LoadTest {
// simple connection to server // simple connection to server
// monitor other players // monitor other players
LoadPlayer monitor = new LoadPlayer("monitor"); LoadPlayer monitor = new LoadPlayer("mon");
Assert.assertTrue(monitor.session.isConnected()); Assert.assertTrue(monitor.session.isConnected());
int startUsersCount = monitor.getAllRoomUsers().size(); int startUsersCount = monitor.getAllRoomUsers().size();
int minimumSleepTime = 2000; int minimumSleepTime = 2000;
@ -150,11 +150,11 @@ public class LoadTest {
public void test_TwoUsersPlayGameUntilEnd() { public void test_TwoUsersPlayGameUntilEnd() {
// monitor other players // monitor other players
LoadPlayer monitor = new LoadPlayer("monitor"); LoadPlayer monitor = new LoadPlayer("mon");
// users // users
LoadPlayer player1 = new LoadPlayer("1"); LoadPlayer player1 = new LoadPlayer("user1");
LoadPlayer player2 = new LoadPlayer("2"); LoadPlayer player2 = new LoadPlayer("user2");
// game by user 1 // game by user 1
GameTypeView gameType = prepareGameType(player1.session); GameTypeView gameType = prepareGameType(player1.session);
@ -213,7 +213,7 @@ public class LoadTest {
Assert.assertFalse("need allowed sets", deckAllowedSets.isEmpty()); Assert.assertFalse("need allowed sets", deckAllowedSets.isEmpty());
// monitor and game source // monitor and game source
LoadPlayer monitor = new LoadPlayer("monitor", true); LoadPlayer monitor = new LoadPlayer("mon", true);
// game by monitor // game by monitor
GameTypeView gameType = prepareGameType(monitor.session); GameTypeView gameType = prepareGameType(monitor.session);
@ -533,7 +533,7 @@ public class LoadTest {
} }
public LoadPlayer(String userPrefix, boolean joinGameChat) { public LoadPlayer(String userPrefix, boolean joinGameChat) {
this.userName = TEST_USER_NAME + "_" + userPrefix + "_" + RandomUtil.nextInt(10000); this.userName = TEST_USER_NAME_GLOBAL_PREFIX + userPrefix + "_" + RandomUtil.nextInt(10000);
this.connection = createSimpleConnection(this.userName); this.connection = createSimpleConnection(this.userName);
this.client = new SimpleMageClient(joinGameChat); this.client = new SimpleMageClient(joinGameChat);
this.session = new SessionImpl(this.client); this.session = new SessionImpl(this.client);
@ -541,6 +541,8 @@ public class LoadTest {
this.session.connect(this.connection); this.session.connect(this.connection);
this.client.setSession(this.session); this.client.setSession(this.session);
this.roomID = this.session.getMainRoomId(); this.roomID = this.session.getMainRoomId();
Assert.assertTrue("client must be connected to server", this.session.isServerReady());
} }
public ArrayList<UsersView> getAllRoomUsers() { public ArrayList<UsersView> getAllRoomUsers() {