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

Documentacion pruebas de carga #195

Merged
merged 9 commits into from
Apr 29, 2024
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
Binary file added docs/images/add100Users.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/add1User.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/playGame1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/playGame20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions docs/src/13_testability.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,30 @@ ifndef::imagesdir[:imagesdir: ../images]
Testability is a crucial aspect of software development. It refers to the ease with which a software system can be tested to ensure its correctness and reliability. By writing tests, developers can verify that their code behaves as expected and identify any potential issues or bugs. There are various types of tests that can be performed, such as unit tests, integration tests, and end-to-end tests. Unit tests focus on testing individual components or functions in isolation, while integration tests verify the interaction between different components. End-to-end tests simulate real-world scenarios to ensure the entire system functions correctly.

To achieve good testability, it is important to write code that is modular, decoupled, and follows best practices such as dependency injection. Additionally, using testing frameworks and tools can simplify the process of writing and executing tests.


=== Load Testing
These tests will focus on evaluating the performance of our system under high traffic and heavy usage conditions. This type of testing is crucial to identify bottlenecks and ensure that our application can effectively handle the volume of users and transactions expected in production, without compromising performance and stability.


Initially, a test was carried out with the following procedure:
1. Create a new user
2. Log in with this new user
3. View the main page

image::add1User.png[title="1 User"]
image::add20Users.png[title="20 User"]
image::add100Users.png[title="100 User"]


Then, a slightly more complex test was then performed, which followed the following procedure:
1. Log in to the app
2. View the main page
3. Play a new game
4. View the game history
5. View the previous game specific data
6. View the history of questions

image::playGame1.png[title="1 User"]
image::playGame20.png[title="20 User"]
image::playGame100.png[title="100 User"]
Binary file added docs/src/add20Users.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/playGame100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added webapp/AddUserSimulation.class
Binary file not shown.
Binary file added webapp/PlayGameSimulation.class
Binary file not shown.
11 changes: 11 additions & 0 deletions webapp/e2e/features/historial-form.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Feature: Visible user logged history

Scenario: The user is not loged in the site
Given A not loged user
When Press history
Then Redirected to login

Scenario: The user register in the site so he can see history
Given A unregistered user, fill the register
When I press history
Then I see my history
85 changes: 85 additions & 0 deletions webapp/e2e/steps/historial-form.steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
const puppeteer = require('puppeteer');
const { defineFeature, loadFeature }=require('jest-cucumber');
const setDefaultOptions = require('expect-puppeteer').setDefaultOptions
const feature = loadFeature('./features/historial-form.feature');

let page;
let browser;

defineFeature(feature, test => {

let username = "";
let password = "";

beforeAll(async () => {
browser = process.env.GITHUB_ACTIONS
? await puppeteer.launch()
: await puppeteer.launch({ headless: false, slowMo: 100 });
page = await browser.newPage();
//Way of setting up the timeout
setDefaultOptions({ timeout: 10000 })

await page
.goto("http://localhost:3000/", {
waitUntil: "networkidle0",
})
.catch(() => {});
});

test('The user is not logged in the site', ({given,when,then}) => {

given('A not logged user', async () => {
username = "pablo";
password = "12345";
});

when('Press history', async () => {
await page.goto("http://localhost:3000/getgamehistory", {
waitUntil: "networkidle0",
}).catch(() => {});
});

then('Redirected to login', async () => {
await expect(page).toMatchElement('button[title="entrar"]');
});
},300000);


test('The user is not registered in the site', ({given,when,then}) => {


given('A unregistered user, fill the register', async () => {
await page.goto("http://localhost:3000/sign-up", {
waitUntil: "networkidle0",
}).catch(() => {});
//Registrar al user
await expect(page).toFill('input[name="username"]', username);
await expect(page).toFill('input[name="password"]', password);
await expect(page).toClick('button[name="registrarsePage"]');
await page.waitForNavigation({
waitUntil: 'networkidle0'
});
});

when('I fill the data in the form and press submit', async () => {
await page.waitForSelector('[data-testid="historial-user"]', {
visible: true,
});
await page.click('[data-testid="historial-user"]');
});

then('I see my history', async () => {
await expect(page).toMatchElement('th', { text: 'Fecha'});
await expect(page).toMatchElement('th', { text: 'Tiempo de partida'});
await expect(page).toMatchElement('th', { text: 'Porcentaje de aciertos'});
await expect(page).toMatchElement('th', { text: 'Número de preguntas'});
await expect(page).toMatchElement('th', { text: 'Número de aciertos'});
await expect(page).toMatchElement('th', { text: 'Número de fallos'});
});
},300000);

afterAll(async ()=>{
browser.close()
})

});
6 changes: 6 additions & 0 deletions webapp/e2e/test-environment-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@ let mongoserver;
let userservice;
let authservice;
let gatewayservice;
let questionservice;
let questionhistoryservice;

async function startServer() {
console.log('Starting MongoDB memory server...');
mongoserver = await MongoMemoryServer.create();
const mongoUri = mongoserver.getUri();
process.env.MONGODB_URI = mongoUri;
process.env.SECRET_KEY = '123456789';
console.log(process.env.MONGODB_URI)
userservice = await require("../../users/userservice/user-service");
authservice = await require("../../users/authservice/auth-service");
gatewayservice = await require("../../gatewayservice/gateway-service");
questionservice = await require("../../questions/creationservice");
questionhistoryservice = await require("../../questions/retrieveservice");
}

startServer();