Skip to content

Commit

Permalink
fix: use containers names for federation-server integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordy Cabannes authored and jcabannes committed Apr 23, 2024
1 parent 029c1bb commit b99ff1d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 58 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
81 changes: 23 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,17 @@ 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 +247,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 +267,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 +717,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 +741,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

0 comments on commit b99ff1d

Please sign in to comment.