From a4ba79ae695849d279f7b75c02f0e4e3905f3b0d Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 6 Jan 2025 08:58:11 +0000 Subject: [PATCH] Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../e2e/sliding-sync/sliding-sync.spec.ts | 3 +- playwright/services.ts | 22 +++++++++--- playwright/testcontainers/synapse.ts | 2 +- playwright/testcontainers/utils.ts | 36 +++++++++++++++++++ 4 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 playwright/testcontainers/utils.ts diff --git a/playwright/e2e/sliding-sync/sliding-sync.spec.ts b/playwright/e2e/sliding-sync/sliding-sync.spec.ts index d105904a48..0ddfabc549 100644 --- a/playwright/e2e/sliding-sync/sliding-sync.spec.ts +++ b/playwright/e2e/sliding-sync/sliding-sync.spec.ts @@ -18,10 +18,11 @@ const test = base.extend<{ testRoom: { roomId: string; name: string }; joinedBot: Bot; }>({ - slidingSyncProxy: async ({ network, postgres, page, homeserver }, use, testInfo) => { + slidingSyncProxy: async ({ logger, network, postgres, page, homeserver }, use, testInfo) => { const container = await new GenericContainer("ghcr.io/matrix-org/sliding-sync:v0.99.3") .withNetwork(network) .withExposedPorts(8008) + .withLogConsumer(logger.getConsumer("sliding-sync-proxy")) .withEnvironment({ SYNCV3_SECRET: "bwahahaha", SYNCV3_DB: `user=postgres dbname=postgres password=${postgres.getPassword()} host=${postgres.getHost()} sslmode=disable`, diff --git a/playwright/services.ts b/playwright/services.ts index e85fd45ccf..b1ab5c6a98 100644 --- a/playwright/services.ts +++ b/playwright/services.ts @@ -12,8 +12,11 @@ import { PostgreSqlContainer, StartedPostgreSqlContainer } from "@testcontainers import { StartedSynapseContainer, SynapseConfigOptions, SynapseContainer } from "./testcontainers/synapse.ts"; import { MatrixAuthenticationServiceContainer } from "./testcontainers/mas.ts"; +import { ContainerLogger } from "./testcontainers/utils.ts"; export interface Services { + logger: ContainerLogger; + network: StartedNetwork; postgres: StartedPostgreSqlContainer; @@ -26,18 +29,24 @@ export interface Services { mas: StartedTestContainer; } -// TODO logs export const test = base.extend({ + // eslint-disable-next-line no-empty-pattern + logger: async ({}, use, testInfo) => { + const logger = new ContainerLogger(); + await use(logger); + await logger.testFinished(testInfo); + }, // eslint-disable-next-line no-empty-pattern network: async ({}, use) => { const network = await new Network().start(); await use(network); await network.stop(); }, - postgres: async ({ network }, use) => { + postgres: async ({ logger, network }, use) => { const container = await new PostgreSqlContainer() .withNetwork(network) .withNetworkAliases("postgres") + .withLogConsumer(logger.getConsumer("postgres")) .withTmpFs({ "/dev/shm/pgdata/data": "", }) @@ -59,11 +68,12 @@ export const test = base.extend({ await container.stop(); }, - mailhog: async ({ network }, use) => { + mailhog: async ({ logger, network }, use) => { const container = await new GenericContainer("mailhog/mailhog:latest") .withNetwork(network) .withNetworkAliases("mailhog") .withExposedPorts(8025) + .withLogConsumer(logger.getConsumer("mailhog")) .withWaitStrategy(Wait.forListeningPorts()) .start(); await use(container); @@ -78,20 +88,22 @@ export const test = base.extend({ const container = new SynapseContainer(request); await use(container); }, - homeserver: async ({ network, _homeserver: homeserver, synapseConfigOptions }, use) => { + homeserver: async ({ logger, network, _homeserver: homeserver, synapseConfigOptions }, use) => { const container = await homeserver .withNetwork(network) .withNetworkAliases("homeserver") + .withLogConsumer(logger.getConsumer("synapse")) .withConfig(synapseConfigOptions) .start(); await use(container); await container.stop(); }, - mas: async ({ network }, use) => { + mas: async ({ logger, network }, use) => { const container = await new MatrixAuthenticationServiceContainer() .withNetwork(network) .withNetworkAliases("mas") + .withLogConsumer(logger.getConsumer("mas")) .withConfig({ clients: [ { diff --git a/playwright/testcontainers/synapse.ts b/playwright/testcontainers/synapse.ts index 33a42c1a68..0e70e0d960 100644 --- a/playwright/testcontainers/synapse.ts +++ b/playwright/testcontainers/synapse.ts @@ -94,7 +94,7 @@ const DEFAULT_CONFIG = { burst_count: 10000, }, }, - media_store_path: "/media", + media_store_path: "/data/media_store", max_upload_size: "50M", max_image_pixels: "32M", dynamic_thumbnails: false, diff --git a/playwright/testcontainers/utils.ts b/playwright/testcontainers/utils.ts new file mode 100644 index 0000000000..58afcce138 --- /dev/null +++ b/playwright/testcontainers/utils.ts @@ -0,0 +1,36 @@ +/* +Copyright 2024 New Vector Ltd. + +SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only +Please see LICENSE files in the repository root for full details. +*/ + +import { TestInfo } from "@playwright/test"; +import { Readable } from "stream"; + +export class ContainerLogger { + private logs: Record = {}; + + public getConsumer(container: string) { + this.logs[container] = ""; + return (stream: Readable) => { + stream.on("data", (chunk) => { + this.logs[container] += chunk.toString(); + }); + stream.on("err", (chunk) => { + this.logs[container] += "ERR " + chunk.toString(); + }); + }; + } + + public async testFinished(testInfo: TestInfo) { + if (testInfo.status !== "passed") { + for (const container in this.logs) { + await testInfo.attach(container, { + body: this.logs[container], + contentType: "text/plain", + }); + } + } + } +}