Skip to content

Commit

Permalink
fix: set explicit test containers names
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordy Cabannes committed Mar 22, 2024
1 parent 7551a67 commit ca880d3
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 115 deletions.
10 changes: 10 additions & 0 deletions packages/federation-server/src/__testData__/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version: '3.8'
services:
postgresql:
image: postgres:13-bullseye
container_name: postgresql
volumes:
- ./synapse-data/matrix.example.com.log.config:/data/matrix.example.com.log.config
- ./db/init-synapse-db.sh:/docker-entrypoint-initdb.d/init-synapse-db.sh
Expand All @@ -23,6 +24,7 @@ services:

synapse-federation: &synapse_template
image: matrixdotorg/synapse:v1.89.0
container_name: synapse-federation
volumes:
- ./synapse-data:/data
- ./nginx/ssl/ca.pem:/etc/ssl/certs/ca.pem
Expand All @@ -44,6 +46,7 @@ services:

synapse-1:
<<: *synapse_template
container_name: synapse-1
environment:
- UID=${MYUID}
- VIRTUAL_PORT=8008
Expand All @@ -52,6 +55,7 @@ services:

synapse-2:
<<: *synapse_template
container_name: synapse-2
environment:
- UID=${MYUID}
- VIRTUAL_PORT=8008
Expand All @@ -60,6 +64,7 @@ services:

synapse-3:
<<: *synapse_template
container_name: synapse-3
environment:
- UID=${MYUID}
- VIRTUAL_PORT=8008
Expand Down Expand Up @@ -93,6 +98,7 @@ services:

federation-server:
image: federation-server
container_name: federation-server
build:
context: ../../../..
dockerfile: ./packages/federation-server/Dockerfile
Expand All @@ -117,6 +123,7 @@ services:

identity-server-1: &identity-server-template
image: identity-server
container_name: identity-server-1
build:
context: ../../../..
dockerfile: ./packages/federation-server/src/__testData__/identity-server/Dockerfile
Expand All @@ -139,6 +146,7 @@ services:

identity-server-2:
<<: *identity-server-template
container_name: identity-server-2
depends_on:
annuaire:
condition: service_started
Expand All @@ -156,6 +164,7 @@ services:

identity-server-3:
<<: *identity-server-template
container_name: identity-server-3
depends_on:
annuaire:
condition: service_started
Expand All @@ -173,6 +182,7 @@ services:

nginx-proxy:
image: nginxproxy/nginx-proxy
container_name: nginx-proxy
ports:
- 443:443
volumes:
Expand Down
82 changes: 24 additions & 58 deletions packages/federation-server/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Hash } from '@twake/crypto'
import dockerComposeV1, { v2 as dockerComposeV2 } from 'docker-compose'
import express from 'express'
import fs from 'fs'
import type * as http from 'http'
Expand Down Expand Up @@ -57,7 +56,6 @@ describe('Federation server', () => {
})

describe('Integration tests', () => {
let containerNameSuffix: string
let startedCompose: StartedDockerComposeEnvironment
let identity1IPAddress: string
let identity2IPAddress: string
Expand Down Expand Up @@ -172,43 +170,18 @@ describe('Federation server', () => {
syswideCas.addCAs(
path.join(pathToTestDataFolder, 'nginx', 'ssl', 'ca.pem')
)
Promise.allSettled([dockerComposeV1.version(), dockerComposeV2.version()])
// eslint-disable-next-line @typescript-eslint/promise-function-async
.then((results) => {
const promiseSucceededIndex = results.findIndex(
(res) => res.status === 'fulfilled'
)
if (promiseSucceededIndex === -1) {
throw new Error('Docker compose is not installed')
}
containerNameSuffix = promiseSucceededIndex === 0 ? '_' : '-'
return new DockerComposeEnvironment(
path.join(pathToTestDataFolder),
'docker-compose.yml'
)
.withEnvironment({ MYUID: os.userInfo().uid.toString() })
.withWaitStrategy(
`postgresql${containerNameSuffix}1`,
Wait.forHealthCheck()
)
.withWaitStrategy(
`synapse-federation${containerNameSuffix}1`,
Wait.forHealthCheck()
)
.withWaitStrategy(
`synapse-1${containerNameSuffix}1`,
Wait.forHealthCheck()
)
.withWaitStrategy(
`synapse-2${containerNameSuffix}1`,
Wait.forHealthCheck()
)
.withWaitStrategy(
`synapse-3${containerNameSuffix}1`,
Wait.forHealthCheck()
)
.up()
})

new DockerComposeEnvironment(
path.join(pathToTestDataFolder),
'docker-compose.yml'
)
.withEnvironment({ MYUID: os.userInfo().uid.toString() })
.withWaitStrategy('postgresql', Wait.forHealthCheck())
.withWaitStrategy('synapse-federation', Wait.forHealthCheck())
.withWaitStrategy('synapse-1', Wait.forHealthCheck())
.withWaitStrategy('synapse-2', Wait.forHealthCheck())
.withWaitStrategy('synapse-3', Wait.forHealthCheck())
.up()
// eslint-disable-next-line @typescript-eslint/promise-function-async
.then((upResult) => {
startedCompose = upResult
Expand Down Expand Up @@ -275,10 +248,10 @@ describe('Federation server', () => {

beforeAll((done) => {
identity1IPAddress = startedCompose
.getContainer(`identity-server-1${containerNameSuffix}1`)
.getContainer(`identity-server-1`)
.getIpAddress('test')
identity2IPAddress = startedCompose
.getContainer(`identity-server-2${containerNameSuffix}1`)
.getContainer(`identity-server-2`)
.getIpAddress('test')

confOriginalContent = fs.readFileSync(
Expand All @@ -295,9 +268,8 @@ describe('Federation server', () => {
'utf-8'
)

federationServerContainer = startedCompose.getContainer(
`federation-server${containerNameSuffix}1`
)
federationServerContainer =
startedCompose.getContainer('federation-server')

federationServerContainer
.restart()
Expand Down Expand Up @@ -746,25 +718,19 @@ describe('Federation server', () => {
'Certificates files for federation server has not been created'
)
return Promise.all([
startedCompose
.getContainer(`identity-server-1${containerNameSuffix}1`)
.restart(),
startedCompose
.getContainer(`identity-server-2${containerNameSuffix}1`)
.restart(),
startedCompose
.getContainer(`identity-server-3${containerNameSuffix}1`)
.restart()
startedCompose.getContainer('identity-server-1').restart(),
startedCompose.getContainer('identity-server-2').restart(),
startedCompose.getContainer('identity-server-3').restart()
])
})
// eslint-disable-next-line @typescript-eslint/promise-function-async
.then(() => {
identity1IPAddress = startedCompose
.getContainer(`identity-server-1${containerNameSuffix}1`)
.getContainer(`identity-server-1`)
.getIpAddress('test')

identity2IPAddress = startedCompose
.getContainer(`identity-server-2${containerNameSuffix}1`)
.getContainer(`identity-server-2`)
.getIpAddress('test')

const testConfig: Config = {
Expand All @@ -776,16 +742,16 @@ describe('Federation server', () => {
database_user: 'twake',
database_password: 'twake!1',
database_host: `${startedCompose
.getContainer(`postgresql${containerNameSuffix}1`)
.getContainer(`postgresql`)
.getHost()}:5432`,
database_name: 'federation',
ldap_base: 'dc=example,dc=com',
ldap_uri: `ldap://${startedCompose
.getContainer(`postgresql${containerNameSuffix}1`)
.getContainer(`postgresql`)
.getHost()}:389`,
matrix_database_engine: 'pg',
matrix_database_host: `${startedCompose
.getContainer(`postgresql${containerNameSuffix}1`)
.getContainer(`postgresql`)
.getHost()}:5432`,
matrix_database_name: 'synapsefederation',
matrix_database_user: 'synapse',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version: '3.8'
services:
synapse:
image: matrixdotorg/synapse:v1.89.0
container_name: synapse-tom-1
volumes:
- ./synapse-data:/data
- ./nginx/ssl/auth.example.com.crt:/etc/ssl/certs/ca-certificates.crt
Expand Down
23 changes: 2 additions & 21 deletions packages/tom-server/src/application-server/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { type TwakeLogger } from '@twake/logger'
import { type AppServiceOutput } from '@twake/matrix-application-server/src/utils'
import { type DbGetResult } from '@twake/matrix-identity-server'
import dockerComposeV1, { v2 as dockerComposeV2 } from 'docker-compose'
import express from 'express'
import fs from 'fs'
import type * as http from 'http'
Expand Down Expand Up @@ -218,7 +217,6 @@ describe('ApplicationServer', () => {
let appServiceToken: string
let newRoomId: string
let rSkywalkerMatrixToken: string
let containerNameSuffix: string

beforeAll((done) => {
syswideCas.addCAs(
Expand All @@ -241,30 +239,13 @@ describe('ApplicationServer', () => {
).as_token
deleteUserDB(testConfig)
// eslint-disable-next-line @typescript-eslint/promise-function-async
.then((_) =>
Promise.allSettled([
dockerComposeV1.version(),
dockerComposeV2.version()
])
)
// eslint-disable-next-line @typescript-eslint/promise-function-async
.then((results) => {
const promiseSucceededIndex = results.findIndex(
(res) => res.status === 'fulfilled'
)
if (promiseSucceededIndex === -1) {
throw new Error('Docker compose is not installed')
}
containerNameSuffix = promiseSucceededIndex === 0 ? '_' : '-'
.then((_) => {
return new DockerComposeEnvironment(
path.join(pathToTestDataFolder),
'docker-compose.yml'
)
.withEnvironment({ MYUID: os.userInfo().uid.toString() })
.withWaitStrategy(
`synapse${containerNameSuffix}1`,
Wait.forHealthCheck()
)
.withWaitStrategy('synapse-tom-1', Wait.forHealthCheck())
.up()
})
// eslint-disable-next-line @typescript-eslint/promise-function-async
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ networks:
services:
postgresql:
image: postgres:13-bullseye
container_name: postgresql-tom
volumes:
- ./synapse-data/matrix.example.com.log.config:/data/matrix.example.com.log.config
- ./db/init-synapse-db.sh:/docker-entrypoint-initdb.d/init-synapse-db.sh
Expand All @@ -26,6 +27,7 @@ services:

synapse:
image: matrixdotorg/synapse:v1.89.0
container_name: synapse-tom
volumes:
- ./synapse-data:/data
- ./nginx/ssl/ca.pem:/etc/ssl/certs/ca.pem
Expand Down Expand Up @@ -85,6 +87,7 @@ services:

nginx-proxy:
image: nginxproxy/nginx-proxy
container_name: nginx-proxy-tom
ports:
- 445:443
volumes:
Expand Down
47 changes: 11 additions & 36 deletions packages/tom-server/src/search-engine-api/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { type TwakeLogger } from '@twake/logger'
import dockerComposeV1, { v2 as dockerComposeV2 } from 'docker-compose'
import express from 'express'
import fs from 'fs'
import type * as http from 'http'
Expand Down Expand Up @@ -46,7 +45,6 @@ describe('Search engine API - Integration tests', () => {
const matrixServer = defaultConfig.matrix_server
let openSearchContainer: GenericContainer
let openSearchStartedContainer: StartedTestContainer
let containerNameSuffix: string
let startedCompose: StartedDockerComposeEnvironment
let tokens: Record<string, string> = {
askywalker: '',
Expand Down Expand Up @@ -312,31 +310,14 @@ describe('Search engine API - Integration tests', () => {

beforeAll((done) => {
syswideCas.addCAs(path.join(pathToTestDataFolder, 'nginx', 'ssl', 'ca.pem'))
Promise.allSettled([dockerComposeV1.version(), dockerComposeV2.version()])
// eslint-disable-next-line @typescript-eslint/promise-function-async
.then((results) => {
const promiseSucceededIndex = results.findIndex(
(res) => res.status === 'fulfilled'
)
if (promiseSucceededIndex === -1) {
throw new Error('Docker compose is not installed')
}
containerNameSuffix = promiseSucceededIndex === 0 ? '_' : '-'
return new DockerComposeEnvironment(
path.join(pathToTestDataFolder),
'docker-compose.yml'
)
.withEnvironment({ MYUID: os.userInfo().uid.toString() })
.withWaitStrategy(
`postgresql${containerNameSuffix}1`,
Wait.forHealthCheck()
)
.withWaitStrategy(
`synapse${containerNameSuffix}1`,
Wait.forHealthCheck()
)
.up()
})
new DockerComposeEnvironment(
path.join(pathToTestDataFolder),
'docker-compose.yml'
)
.withEnvironment({ MYUID: os.userInfo().uid.toString() })
.withWaitStrategy('postgresql-tom', Wait.forHealthCheck())
.withWaitStrategy('synapse-tom', Wait.forHealthCheck())
.up()
// eslint-disable-next-line @typescript-eslint/promise-function-async
.then((upResult) => {
startedCompose = upResult
Expand All @@ -357,9 +338,7 @@ describe('Search engine API - Integration tests', () => {
retries: 3
})
.withNetworkMode(
startedCompose
.getContainer(`nginx-proxy${containerNameSuffix}1`)
.getNetworkNames()[0]
startedCompose.getContainer('nginx-proxy-tom').getNetworkNames()[0]
)
.withEnvironment({
'discovery.type': 'single-node',
Expand All @@ -375,9 +354,7 @@ describe('Search engine API - Integration tests', () => {
// eslint-disable-next-line @typescript-eslint/promise-function-async
.then((startedContainer) => {
openSearchStartedContainer = startedContainer
return startedCompose
.getContainer(`nginx-proxy${containerNameSuffix}1`)
.restart()
return startedCompose.getContainer('nginx-proxy-tom').restart()
})
// eslint-disable-next-line @typescript-eslint/promise-function-async
.then(() => {
Expand Down Expand Up @@ -985,9 +962,7 @@ describe('Search engine API - Integration tests', () => {

console.info('Server closed. Restarting.')

await startedCompose
.getContainer(`nginx-proxy${containerNameSuffix}1`)
.restart()
await startedCompose.getContainer('nginx-proxy-tom').restart()

twakeServer = new TwakeServer(testConfig as Config)
app = express()
Expand Down

0 comments on commit ca880d3

Please sign in to comment.