Adding a reconnect feature in case first Pusher request fails
Now, if the first pusher request fails, a waiting message will be displayed and the application will reconnect when the pusher comes back alive or the network connection is established again.
This commit is contained in:
parent
9eb4206fe0
commit
fcf0888864
17 changed files with 981 additions and 32 deletions
|
@ -1,13 +1,38 @@
|
|||
import {assertLogMessage} from "./utils/log";
|
||||
|
||||
const fs = require('fs')
|
||||
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";
|
||||
|
||||
// Note: we are also testing that we can connect if the URL contains a random query string
|
||||
fixture `Variables`
|
||||
.page `http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/Cache/variables_tmp.json?somerandomparam=1`;
|
||||
fixture `Reconnection`
|
||||
.page `http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/mousewheel.json`;
|
||||
|
||||
test("Test that connection can succeed even if WorkAdventure starts while pusher is down", async (t: TestController) => {
|
||||
// Let's stop the pusher
|
||||
const container = await findContainer('pusher');
|
||||
await stopContainer(container);
|
||||
|
||||
const errorMessage = Selector('.error-div');
|
||||
|
||||
await t
|
||||
.navigateTo('http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/mousewheel.json')
|
||||
.expect(errorMessage.innerText).contains('Unable to connect to WorkAdventure')
|
||||
|
||||
await startContainer(container);
|
||||
|
||||
await t.useRole(userAlice);
|
||||
|
||||
t.ctx.passed = true;
|
||||
}).after(async t => {
|
||||
if (!t.ctx.passed) {
|
||||
console.log("Test failed. Browser logs:")
|
||||
console.log(await t.getBrowserConsoleMessages());
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
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');
|
||||
|
@ -18,11 +43,9 @@ test("Test that variables cache in the back don't prevent setting a variable in
|
|||
// Let's REPLACE the map by a map that has a new variable
|
||||
// At this point, the back server contains a cache of the old map (with no variables)
|
||||
fs.copyFileSync('../maps/tests/Variables/Cache/variables_cache_2.json', '../maps/tests/Variables/Cache/variables_tmp.json');
|
||||
await t.openWindow('http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/Cache/variables_tmp.json');
|
||||
|
||||
await t.resizeWindow(960, 800);
|
||||
|
||||
await t.useRole(userAlice);
|
||||
await t.openWindow('http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/Cache/variables_tmp.json')
|
||||
.resizeWindow(960, 800)
|
||||
.useRole(userAlice);
|
||||
//.takeScreenshot('after_switch.png');
|
||||
|
||||
// Let's check we successfully manage to save the variable value.
|
||||
|
@ -35,3 +58,4 @@ test("Test that variables cache in the back don't prevent setting a variable in
|
|||
console.log(await t.getBrowserConsoleMessages());
|
||||
}
|
||||
});
|
||||
*/
|
51
tests/tests/utils/containers.ts
Normal file
51
tests/tests/utils/containers.ts
Normal file
|
@ -0,0 +1,51 @@
|
|||
//import Docker from "dockerode";
|
||||
//import * as Dockerode from "dockerode";
|
||||
import Dockerode = require( 'dockerode')
|
||||
|
||||
|
||||
/**
|
||||
* Returns a container ID based on the container name.
|
||||
*/
|
||||
export async function findContainer(name: string): Promise<Dockerode.ContainerInfo> {
|
||||
const docker = new Dockerode();
|
||||
|
||||
const containers = await docker.listContainers();
|
||||
|
||||
const foundContainer = containers.find((container) => container.State === 'running' && container.Names.find((containerName) => containerName.includes(name)));
|
||||
|
||||
if (foundContainer === undefined) {
|
||||
throw new Error('Could not find a running container whose name contains "'+name+'"');
|
||||
}
|
||||
|
||||
return foundContainer;
|
||||
}
|
||||
|
||||
export async function stopContainer(container: Dockerode.ContainerInfo): Promise<void> {
|
||||
const docker = new Dockerode();
|
||||
|
||||
await docker.getContainer(container.Id).stop();
|
||||
}
|
||||
|
||||
export async function startContainer(container: Dockerode.ContainerInfo): Promise<void> {
|
||||
const docker = new Dockerode();
|
||||
|
||||
await docker.getContainer(container.Id).start();
|
||||
}
|
||||
|
||||
export async function rebootBack(): Promise<void> {
|
||||
const container = await findContainer('back');
|
||||
await stopContainer(container);
|
||||
await startContainer(container);
|
||||
}
|
||||
|
||||
export async function rebootPusher(): Promise<void> {
|
||||
const container = await findContainer('pusher');
|
||||
await stopContainer(container);
|
||||
await startContainer(container);
|
||||
}
|
||||
|
||||
export async function rebootRedis(): Promise<void> {
|
||||
const container = await findContainer('redis');
|
||||
await stopContainer(container);
|
||||
await startContainer(container);
|
||||
}
|
80
tests/tests/variables.ts
Normal file
80
tests/tests/variables.ts
Normal file
|
@ -0,0 +1,80 @@
|
|||
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";
|
||||
|
||||
// Note: we are also testing that passing a random query parameter does not cause any issue.
|
||||
fixture `Variables`
|
||||
.page `http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json?somerandomparam=1`;
|
||||
|
||||
test("Test that variables storage works", async (t: TestController) => {
|
||||
|
||||
const variableInput = Selector('#textField');
|
||||
|
||||
await Promise.all([
|
||||
rebootBack(),
|
||||
rebootRedis(),
|
||||
rebootPusher(),
|
||||
]);
|
||||
|
||||
await t.useRole(userAlice)
|
||||
.switchToIframe("#cowebsite-buffer iframe")
|
||||
.debug()
|
||||
.expect(variableInput.value).eql('default value')
|
||||
.typeText(variableInput, 'new value')
|
||||
.switchToPreviousWindow()
|
||||
// reload
|
||||
/*.navigateTo('http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/shared_variables.json')
|
||||
.switchToIframe("#cowebsite-buffer iframe")
|
||||
.expect(variableInput.value).eql('new value')*/
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
const backContainer = await findContainer('back');
|
||||
|
||||
await stopContainer(backContainer);
|
||||
|
||||
await startContainer(backContainer);
|
||||
*/
|
||||
|
||||
|
||||
t.ctx.passed = true;
|
||||
}).after(async t => {
|
||||
if (!t.ctx.passed) {
|
||||
console.log("Test failed. Browser logs:")
|
||||
console.log(await t.getBrowserConsoleMessages());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
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');
|
||||
|
||||
await t.useRole(userAlice);
|
||||
//.takeScreenshot('before_switch.png');
|
||||
|
||||
// Let's REPLACE the map by a map that has a new variable
|
||||
// At this point, the back server contains a cache of the old map (with no variables)
|
||||
fs.copyFileSync('../maps/tests/Variables/Cache/variables_cache_2.json', '../maps/tests/Variables/Cache/variables_tmp.json');
|
||||
await t.openWindow('http://play.workadventure.localhost/_/global/maps.workadventure.localhost/tests/Variables/Cache/variables_tmp.json')
|
||||
.resizeWindow(960, 800)
|
||||
.useRole(userAlice);
|
||||
//.takeScreenshot('after_switch.png');
|
||||
|
||||
// Let's check we successfully manage to save the variable value.
|
||||
await assertLogMessage(t, 'SUCCESS!');
|
||||
|
||||
t.ctx.passed = true;
|
||||
}).after(async t => {
|
||||
if (!t.ctx.passed) {
|
||||
console.log("Test failed. Browser logs:")
|
||||
console.log(await t.getBrowserConsoleMessages());
|
||||
}
|
||||
});
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue