tests: fixed error on load tests end (related to #11572), improved logs, improved session lifecycle on load tests;

tests: added additional test for Mana Maze and deep copy (related to #11572);
docs: added more info to network related code;
This commit is contained in:
Oleg Agafonov 2024-01-08 04:03:16 +04:00
parent 98a3d8b947
commit b3c55555a1
12 changed files with 119 additions and 66 deletions

View file

@ -2,19 +2,48 @@ package org.mage.test.cards.single.inv;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import mage.util.CardUtil;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @author JayDi85
*/
@Ignore // TODO: enable after deep copy fix
public class ManaMazeTest extends CardTestPlayerBase {
@Test
@Ignore // TODO: enable after deep copy fix
public void test_DeepCopyWithWatcherAndSelfReference() {
public void test_DeepCopy_WithSelfReference() {
// stack overflow bug: https://github.com/magefree/mage/issues/11572
// list
List<String> sourceList = new ArrayList<>(Arrays.asList("val1", "val2", "val3"));
List<String> copyList = CardUtil.deepCopyObject(sourceList);
Assert.assertNotSame(sourceList, copyList);
Assert.assertEquals(sourceList.size(), copyList.size());
Assert.assertEquals(sourceList.toString(), copyList.toString());
// list with self ref
List<List<Object>> sourceObjectList = new ArrayList<>();
sourceObjectList.add(new ArrayList<>(Arrays.asList("val1", "val2", "val3")));
sourceObjectList.add(new ArrayList<>(Arrays.asList(sourceObjectList)));
List<List<Object>> copyObjectList = CardUtil.deepCopyObject(sourceObjectList);
Assert.assertNotSame(sourceObjectList, copyObjectList);
Assert.assertEquals(sourceObjectList.size(), copyObjectList.size());
Assert.assertEquals(sourceObjectList.get(0).size(), copyObjectList.get(0).size());
Assert.assertEquals(sourceObjectList.get(0).toString(), copyObjectList.get(0).toString());
Assert.assertEquals(sourceObjectList.get(1).size(), copyObjectList.get(1).size());
Assert.assertEquals(sourceObjectList.get(1).toString(), copyObjectList.get(1).toString());
}
@Test
public void test_DeepCopy_WatcherWithSelfReference() {
// stack overflow bug: https://github.com/magefree/mage/issues/11572
// card's watcher can have spell's ref to itself, so deep copy must be able to process it

View file

@ -200,7 +200,7 @@ public class LoadTest {
// playing until game over
while (!player1.client.isGameOver() && !player2.client.isGameOver()) {
checkGame = monitor.getTable(tableId);
logger.warn(checkGame.get().getTableState());
logger.info(checkGame.get().getTableState());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
@ -236,6 +236,7 @@ public class LoadTest {
// playing until game over
gameResult.start();
boolean startToWatching = false;
Date lastActivity = new Date();
while (true) {
GameView gameView = monitor.client.getLastGameView();
@ -243,8 +244,8 @@ public class LoadTest {
TableState state = (checkGame == null ? null : checkGame.getTableState());
if (gameView != null && checkGame != null) {
logger.warn(checkGame.getTableName() + ": ---");
logger.warn(String.format("%s: turn %d, step %s, state %s",
logger.info(checkGame.getTableName() + ": ---");
logger.info(String.format("%s: turn %d, step %s, state %s",
checkGame.getTableName(),
gameView.getTurn(),
gameView.getStep().toString(),
@ -279,6 +280,13 @@ public class LoadTest {
activeInfo
));
});
logger.info(checkGame.getTableName() + ": ---");
}
// ping to keep active session
if ((new Date().getTime() - lastActivity.getTime()) / 1000 > 10) {
monitor.session.ping();
lastActivity = new Date();
}
try {
@ -287,6 +295,9 @@ public class LoadTest {
logger.error(e.getMessage(), e);
}
}
// all done, can disconnect now
monitor.session.connectStop(false, false);
}
@Test