Improving tests, WIP

This commit is contained in:
David Négrier 2021-12-03 09:28:30 +01:00
parent 9bba6069b4
commit 78ee4009c8
11 changed files with 276 additions and 25 deletions

View file

@ -4,7 +4,7 @@ const fs = require('fs');
const Docker = require('dockerode');
import { Selector } from 'testcafe';
import {userAlice} from "./utils/roles";
import {findContainer, rebootBack, rebootPusher, rebootRedis, startContainer, stopContainer} from "./utils/containers";
import {findContainer, rebootBack, rebootPusher, resetRedis, startContainer, stopContainer} from "./utils/containers";
fixture `Reconnection`
.page `http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/mousewheel.json`;

View file

@ -1,7 +1,9 @@
//import Docker from "dockerode";
//import * as Dockerode from "dockerode";
import Dockerode = require( 'dockerode')
const util = require('util');
const exec = util.promisify(require('child_process').exec);
const { execSync } = require('child_process');
/**
* Returns a container ID based on the container name.
@ -33,19 +35,81 @@ export async function startContainer(container: Dockerode.ContainerInfo): Promis
}
export async function rebootBack(): Promise<void> {
const container = await findContainer('back');
let stdout = execSync('docker-compose up --force-recreate -d back', {
cwd: __dirname + '/../../../'
});
/*const container = await findContainer('back');
await stopContainer(container);
await startContainer(container);
await startContainer(container);*/
}
export function rebootTraefik(): void {
let stdout = execSync('docker-compose up --force-recreate -d reverse-proxy', {
cwd: __dirname + '/../../../'
});
//console.log('rebootTraefik', stdout);
}
export async function rebootPusher(): Promise<void> {
const container = await findContainer('pusher');
let stdout = execSync('docker-compose up --force-recreate -d pusher', {
cwd: __dirname + '/../../../'
});
/*const container = await findContainer('pusher');
await stopContainer(container);
await startContainer(container);
await startContainer(container);*/
}
export async function rebootRedis(): Promise<void> {
const container = await findContainer('redis');
await stopContainer(container);
await startContainer(container);
export async function resetRedis(): Promise<void> {
let stdout = execSync('docker-compose stop redis', {
cwd: __dirname + '/../../../'
});
//console.log('rebootRedis', stdout);
stdout = execSync('docker-compose rm -f redis', {
cwd: __dirname + '/../../../'
});
//console.log('rebootRedis', stdout);
stdout = execSync('docker-compose up --force-recreate -d redis', {
cwd: __dirname + '/../../../'
});
//console.log('rebootRedis', stdout);
/*
let stdout = execSync('docker-compose stop redis', {
cwd: __dirname + '/../../../'
});
console.log('stdout:', stdout);
stdout = execSync('docker-compose rm redis', {
cwd: __dirname + '/../../../'
});
//const { stdout, stderr } = await exec('docker-compose down redis');
console.log('stdout:', stdout);
//console.log('stderr:', stderr);
const { stdout2, stderr2 } = await exec('docker-compose up -d redis');
console.log('stdout:', stdout2);
console.log('stderr:', stderr2);
*/
/*const container = await findContainer('redis');
//await stopContainer(container);
//await startContainer(container);
const docker = new Dockerode();
await docker.getContainer(container.Id).stop();
await docker.getContainer(container.Id).remove();
const newContainer = await docker.createContainer(container);
await newContainer.start();*/
}
export function stopRedis(): void {
let stdout = execSync('docker-compose stop redis', {
cwd: __dirname + '/../../../'
});
}
export function startRedis(): void {
let stdout = execSync('docker-compose start redis', {
cwd: __dirname + '/../../../'
});
}

View file

@ -0,0 +1,17 @@
import axios from "axios";
export async function getPusherDump(): Promise<any> {
return (await axios({
url: 'http://pusher.workadventure.localhost/dump?token=123',
method: 'get',
})).data;
}
export async function getBackDump(): Promise<any> {
return (await axios({
url: 'http://api.workadventure.localhost/dump?token=123',
method: 'get',
})).data;
}

View file

@ -1,5 +1,16 @@
import { Role } from 'testcafe';
export const userAliceOnPage = (url: string) => Role(url, async t => {
await t
.typeText('input[name="loginSceneName"]', 'Alice')
.click('button.loginSceneFormSubmit')
.click('button.selectCharacterButtonRight')
.click('button.selectCharacterButtonRight')
.click('button.selectCharacterSceneFormSubmit')
.click('button.letsgo');
});
export const userAlice = Role('http://play.workadventure.localhost/', async t => {
await t
.typeText('input[name="loginSceneName"]', 'Alice')

View file

@ -3,8 +3,17 @@ import {assertLogMessage} from "./utils/log";
const fs = require('fs');
const Docker = require('dockerode');
import { Selector } from 'testcafe';
import {userAlice} from "./utils/roles";
import {findContainer, rebootBack, rebootPusher, rebootRedis, startContainer, stopContainer} from "./utils/containers";
import {userAlice, userAliceOnPage} from "./utils/roles";
import {
findContainer,
rebootBack,
rebootPusher,
resetRedis,
rebootTraefik,
startContainer,
stopContainer, stopRedis, startRedis
} from "./utils/containers";
import {getPusherDump} from "./utils/debug";
// Note: we are also testing that passing a random query parameter does not cause any issue.
fixture `Variables`
@ -14,21 +23,75 @@ test("Test that variables storage works", async (t: TestController) => {
const variableInput = Selector('#textField');
await resetRedis();
await Promise.all([
rebootBack(),
rebootRedis(),
rebootPusher(),
]);
await t.useRole(userAlice)
//const mainWindow = await t.getCurrentWindow();
await t.useRole(userAliceOnPage('http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json?somerandomparam=1'))
.switchToIframe("#cowebsite-buffer iframe")
.expect(variableInput.value).eql('default value')
.selectText(variableInput)
.pressKey('delete')
.typeText(variableInput, 'new value')
.switchToPreviousWindow()
.pressKey('tab')
.switchToMainWindow()
//.switchToWindow(mainWindow)
.wait(500)
// reload
/*.navigateTo('http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json')
.navigateTo('http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json')
.switchToIframe("#cowebsite-buffer iframe")
.expect(variableInput.value).eql('new value')*/
.expect(variableInput.value).eql('new value')
//.debug()
.switchToMainWindow()
//.switchToWindow(mainWindow)
/*
.wait(5000)
//.debug()
.switchToIframe("#cowebsite-buffer iframe")
.expect(variableInput.value).eql('new value')
.switchToMainWindow();*/
// Now, let's kill the reverse proxy to cut the connexion
//console.log('Rebooting traefik');
await rebootTraefik();
//console.log('Rebooting done');
await t
.switchToIframe("#cowebsite-buffer iframe")
.expect(variableInput.value).eql('new value')
stopRedis();
// Redis is stopped, let's try to modify a variable.
await t.selectText(variableInput)
.pressKey('delete')
.typeText(variableInput, 'value set while Redis stopped')
.pressKey('tab')
.switchToMainWindow()
startRedis();
// Navigate to some other map so that the pusher connection is freed.
await t.navigateTo('http://maps.workadventure.localhost/tests/');
// TODO: check that Back and Pusher rooms are unloaded
// TODO: check that Back and Pusher rooms are unloaded
// TODO: check that Back and Pusher rooms are unloaded
// TODO: check that Back and Pusher rooms are unloaded
console.log(await getPusherDump());
await t.navigateTo('http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json')
.switchToIframe("#cowebsite-buffer iframe")
// Redis will reconnect automatically and will store the variable on reconnect!
// So we should see the new value.
.expect(variableInput.value).eql('value set while Redis stopped')
.switchToMainWindow()
@ -50,7 +113,7 @@ test("Test that variables storage works", async (t: TestController) => {
}
});
/*
test("Test that variables cache in the back don't prevent setting a variable in case the map changes", async (t: TestController) => {
// Let's start by visiting a map that DOES not have the variable.
fs.copyFileSync('../maps/tests/Variables/Cache/variables_cache_1.json', '../maps/tests/Variables/Cache/variables_tmp.json');
@ -77,3 +140,4 @@ test("Test that variables cache in the back don't prevent setting a variable in
}
});
*/