mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 04:22:01 -08:00
added random length pauses to load tests
This commit is contained in:
parent
d10bb2ed40
commit
13d267f5a1
4 changed files with 21 additions and 10 deletions
|
|
@ -41,6 +41,7 @@ public class TestClient implements MageClient {
|
|||
|
||||
private Client client;
|
||||
private ServerState serverState;
|
||||
private String userName;
|
||||
private boolean joinedTableFired = false;
|
||||
|
||||
public TestClient() {
|
||||
|
|
@ -48,6 +49,7 @@ public class TestClient implements MageClient {
|
|||
}
|
||||
|
||||
public boolean connect(String userName) {
|
||||
this.userName = userName;
|
||||
Connection connection = new Connection();
|
||||
connection.setHost("localhost");
|
||||
connection.setPort(17171);
|
||||
|
|
@ -91,7 +93,7 @@ public class TestClient implements MageClient {
|
|||
|
||||
@Override
|
||||
public void receiveChatMessage(UUID chatId, ChatMessage message) {
|
||||
logger.info("Recieved message: " + message);
|
||||
logger.info("Recieved message for " + userName + ": " + message.getUsername() + "-" + message.getTime() + "-" + message.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import java.io.FileReader;
|
|||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import mage.server.ServerMain;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Assert;
|
||||
|
|
@ -19,6 +20,7 @@ import org.mage.server.test.TestClient;
|
|||
public abstract class BaseLoadTest {
|
||||
|
||||
protected static final Logger logger = Logger.getLogger(BaseLoadTest.class);
|
||||
protected static final Random rng = new Random();
|
||||
|
||||
protected Map<String, TestClient> users = new HashMap<>();
|
||||
|
||||
|
|
@ -66,6 +68,7 @@ public abstract class BaseLoadTest {
|
|||
TestClient client = new TestClient();
|
||||
client.connect(username);
|
||||
users.put(username, client);
|
||||
pause(10, 50); // wait 10 to 50 ms
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -73,10 +76,19 @@ public abstract class BaseLoadTest {
|
|||
protected void disconnect() {
|
||||
for (TestClient client: users.values()) {
|
||||
client.disconnect(false);
|
||||
pause(10, 50); // wait 10 to 50 ms
|
||||
}
|
||||
logger.info("Finished disconnecting");
|
||||
for (TestClient client: users.values()) {
|
||||
Assert.assertFalse("user did not disconnect", client.isConnected());
|
||||
}
|
||||
}
|
||||
|
||||
protected void pause(int min, int max) {
|
||||
try {
|
||||
Thread.sleep(rng.nextInt(max - min) + min);
|
||||
} catch (InterruptedException ex) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package org.mage.server.test.load;
|
||||
|
||||
import java.util.Random;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.mage.server.test.TestClient;
|
||||
|
||||
|
|
@ -14,7 +14,6 @@ public class ChatLoadTest extends BaseLoadTest {
|
|||
private static final int NUM_TESTS = 50;
|
||||
|
||||
private static final StringBuilder sb = new StringBuilder();
|
||||
private static final Random rng = new Random();
|
||||
|
||||
private static final char[] symbols;
|
||||
static {
|
||||
|
|
@ -29,6 +28,7 @@ public class ChatLoadTest extends BaseLoadTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void chat() {
|
||||
connect(USER_COUNT);
|
||||
|
||||
|
|
@ -42,10 +42,7 @@ public class ChatLoadTest extends BaseLoadTest {
|
|||
String message = randomString();
|
||||
logger.info("Sending chat message#:" + i + " message:" + message);
|
||||
client.sendChatMessage(client.getServerState().getMainRoomId(), message);
|
||||
try {
|
||||
Thread.sleep(rng.nextInt(450) + 50); // sleep between 50 and 500 ms
|
||||
} catch (InterruptedException ex) {
|
||||
}
|
||||
pause(50, 500); // wait 50 to 500 ms
|
||||
}
|
||||
|
||||
disconnect();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package org.mage.server.test.load;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
|
@ -12,14 +11,15 @@ public class ConnectionLoadTest extends BaseLoadTest {
|
|||
private static final Integer USER_COUNT = 400;
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void connectTest() {
|
||||
connect(USER_COUNT);
|
||||
|
||||
logger.info("starting sleep");
|
||||
try {
|
||||
Thread.sleep(60000); // wait for 1 minute -- this allows some ping requests to bounce around
|
||||
Thread.sleep(65000); // wait for aprox. 1 minute -- this allows some ping requests to bounce around
|
||||
} catch (InterruptedException ex) {
|
||||
}
|
||||
logger.info("done sleeping");
|
||||
|
||||
disconnect();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue