workadventure/tests/tests/utils/containers.ts
David Négrier fcf0888864 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.
2021-12-01 14:14:02 +01:00

52 lines
1.6 KiB
TypeScript

//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);
}