Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(load-testing): Improve load tests #316

Merged
merged 2 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/load-testing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,24 @@ This will create a `credentials.csv` file next to the tests.
node ./packages/load-testing/scripts/register-users-to-game.js
```

6. In the admin dashboard, assign players to teams and launch the game. Make sure to have the first step of the game active so the test players can select consumption actions.

The test is now all set. 🚀

### Run

On Fargate:

```bash
npx artillery run:fargate --region us-east-1 --count 35 --output ./packages/load-testing/websocket-load-testing-report.json ./packages/load-testing/websocket-load-testing.yml
```

Or locally:

```bash
npx artillery run --output ./packages/load-testing/websocket-load-testing-report.json ./packages/load-testing/websocket-load-testing.yml
```

Once completed, generate the `html` report using:

```bash
Expand Down
8 changes: 4 additions & 4 deletions packages/load-testing/config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const API_URL = "https://atelierogre-staging.herokuapp.com";
const GAME_CODE = "OBK-3K9";
const GAME_ID = 172;
const GAME_IDS = [182, 183, 184];
const GAME_CODES = ["7KH-HB4", "M84-E17", "YPB-ONS"];
const SECRET_KEY = "xxx";
const USER_COUNT = 200;
const WEBSITE_URL = "https://app-staging.atelierogre.org";

module.exports = {
API_URL,
GAME_CODE,
GAME_ID,
GAME_IDS,
GAME_CODES,
SECRET_KEY,
USER_COUNT,
WEBSITE_URL,
Expand Down
6 changes: 4 additions & 2 deletions packages/load-testing/scripts/generate-users-credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ async function generateUsersCredentials() {
const credentials = new Array(config.USER_COUNT)
.fill(0)
.map((_, i) => generators.generateUserData(i + 1))
.map((userData) => ({
.map((userData, i) => ({
email: userData.email,
token: createToken(userData.email),
gameId: config.GAME_IDS[i % config.GAME_IDS.length],
gameCode: config.GAME_CODES[i % config.GAME_CODES.length],
}));

const fileContent = credentials
.map((c) => `${c.email},${c.token}`)
.map((c) => `${c.email},${c.token},${c.gameId},${c.gameCode}`)
.join("\n");

fs.writeFileSync(path.join(__dirname, "../credentials.csv"), fileContent);
Expand Down
38 changes: 25 additions & 13 deletions packages/load-testing/scripts/register-users-to-game.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,42 @@ const { http } = require("../utils");
registerUsersToGame();

async function registerUsersToGame() {
console.log(`Registering users to game ${config.GAME_CODE}`);
console.log(`Registering users respectively to their game`);

const fileContent = fs.readFileSync(
path.join(__dirname, "../credentials.csv"),
{ encoding: "utf8", flag: "r" }
);

const tokens = fileContent.split("\n").map((line) => line.split(",")[1]);
const usersData = loadUserData();

const BATCH_SIZE = 10;
let i = 0;
while (i < tokens.length) {
let tokenBatch = tokens.slice(i, i + BATCH_SIZE);
await Promise.all(tokenBatch.map(registerUser));
while (i < usersData.length) {
let usersDataBatch = usersData.slice(i, i + BATCH_SIZE);
await Promise.all(usersDataBatch.map(registerUser));
i += BATCH_SIZE;
}

console.log(`Users registered successfully`);
}

async function registerUser(token) {
async function registerUser(userData) {
await http.post(
`${config.API_URL}/api/games/register`,
{ gameCode: config.GAME_CODE },
{ Authorization: `Bearer ${token}` }
{ gameCode: userData.gameCode },
{ Authorization: `Bearer ${userData.token}` }
);
}

function loadUserData() {
const fileContent = fs.readFileSync(
path.join(__dirname, "../credentials.csv"),
{ encoding: "utf8", flag: "r" }
);

return fileContent.split("\n").map((line) => {
const dataChunks = line.split(",");
return {
email: dataChunks[0],
token: dataChunks[1],
gameId: dataChunks[2],
gameCode: dataChunks[3],
};
});
}
12 changes: 8 additions & 4 deletions packages/load-testing/websocket-load-testing-flow.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const config = require("./config");

const USER_ACTION_COUNT = 600;

module.exports = {
testConsumptionActionsLoad,
};
Expand All @@ -8,6 +10,8 @@ async function testConsumptionActionsLoad(page, context) {
const userData = {
email: context.vars.email,
token: context.vars.token,
gameId: context.vars.gameId,
gameCode: context.vars.gameCode,
};

const localStorage = new LocalStorage(page);
Expand All @@ -19,10 +23,10 @@ async function testConsumptionActionsLoad(page, context) {

await page.waitForURL(`${config.WEBSITE_URL}/play/my-games`);

await navigator.goToPlayerActionPage();
await navigator.goToPlayerActionPage(userData.gameId);
const checkboxes = page.getByRole("checkbox");

for (let i = 0; i < 60; i++) {
for (let i = 0; i < USER_ACTION_COUNT; i++) {
await checkboxes.nth(i % 5).click();
await pause(1000);
}
Expand All @@ -37,9 +41,9 @@ class Navigator {
this.page = page;
}

async goToPlayerActionPage() {
async goToPlayerActionPage(gameId) {
await this.page.goto(
`${config.WEBSITE_URL}/play/games/${config.GAME_ID}/persona/actions`
`${config.WEBSITE_URL}/play/games/${gameId}/persona/actions`
);
}

Expand Down
2 changes: 2 additions & 0 deletions packages/load-testing/websocket-load-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ config:
fields:
- "email"
- "token"
- "gameId"
- "gameCode"
processor: "./websocket-load-testing-flow.js"
phases:
- name: "Players connecting to app"
Expand Down
Loading