Skip to content

Commit b99ff1d

Browse files
jcabannes932jcabannes
authored andcommitted
fix: use containers names for federation-server integration tests
1 parent 029c1bb commit b99ff1d

File tree

2 files changed

+33
-58
lines changed

2 files changed

+33
-58
lines changed

packages/federation-server/src/__testData__/docker-compose.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ version: '3.8'
33
services:
44
postgresql:
55
image: postgres:13-bullseye
6+
container_name: postgresql
67
volumes:
78
- ./synapse-data/matrix.example.com.log.config:/data/matrix.example.com.log.config
89
- ./db/init-synapse-db.sh:/docker-entrypoint-initdb.d/init-synapse-db.sh
@@ -23,6 +24,7 @@ services:
2324

2425
synapse-federation: &synapse_template
2526
image: matrixdotorg/synapse:v1.89.0
27+
container_name: synapse-federation
2628
volumes:
2729
- ./synapse-data:/data
2830
- ./nginx/ssl/ca.pem:/etc/ssl/certs/ca.pem
@@ -44,6 +46,7 @@ services:
4446

4547
synapse-1:
4648
<<: *synapse_template
49+
container_name: synapse-1
4750
environment:
4851
- UID=${MYUID}
4952
- VIRTUAL_PORT=8008
@@ -52,6 +55,7 @@ services:
5255

5356
synapse-2:
5457
<<: *synapse_template
58+
container_name: synapse-2
5559
environment:
5660
- UID=${MYUID}
5761
- VIRTUAL_PORT=8008
@@ -60,6 +64,7 @@ services:
6064

6165
synapse-3:
6266
<<: *synapse_template
67+
container_name: synapse-3
6368
environment:
6469
- UID=${MYUID}
6570
- VIRTUAL_PORT=8008
@@ -93,6 +98,7 @@ services:
9398

9499
federation-server:
95100
image: federation-server
101+
container_name: federation-server
96102
build:
97103
context: ../../../..
98104
dockerfile: ./packages/federation-server/Dockerfile
@@ -117,6 +123,7 @@ services:
117123

118124
identity-server-1: &identity-server-template
119125
image: identity-server
126+
container_name: identity-server-1
120127
build:
121128
context: ../../../..
122129
dockerfile: ./packages/federation-server/src/__testData__/identity-server/Dockerfile
@@ -139,6 +146,7 @@ services:
139146

140147
identity-server-2:
141148
<<: *identity-server-template
149+
container_name: identity-server-2
142150
depends_on:
143151
annuaire:
144152
condition: service_started
@@ -156,6 +164,7 @@ services:
156164

157165
identity-server-3:
158166
<<: *identity-server-template
167+
container_name: identity-server-3
159168
depends_on:
160169
annuaire:
161170
condition: service_started
@@ -173,6 +182,7 @@ services:
173182

174183
nginx-proxy:
175184
image: nginxproxy/nginx-proxy
185+
container_name: nginx-proxy
176186
ports:
177187
- 443:443
178188
volumes:

packages/federation-server/src/index.test.ts

Lines changed: 23 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Hash } from '@twake/crypto'
2-
import dockerComposeV1, { v2 as dockerComposeV2 } from 'docker-compose'
32
import express from 'express'
43
import fs from 'fs'
54
import type * as http from 'http'
@@ -57,7 +56,6 @@ describe('Federation server', () => {
5756
})
5857

5958
describe('Integration tests', () => {
60-
let containerNameSuffix: string
6159
let startedCompose: StartedDockerComposeEnvironment
6260
let identity1IPAddress: string
6361
let identity2IPAddress: string
@@ -172,43 +170,17 @@ describe('Federation server', () => {
172170
syswideCas.addCAs(
173171
path.join(pathToTestDataFolder, 'nginx', 'ssl', 'ca.pem')
174172
)
175-
Promise.allSettled([dockerComposeV1.version(), dockerComposeV2.version()])
176-
// eslint-disable-next-line @typescript-eslint/promise-function-async
177-
.then((results) => {
178-
const promiseSucceededIndex = results.findIndex(
179-
(res) => res.status === 'fulfilled'
180-
)
181-
if (promiseSucceededIndex === -1) {
182-
throw new Error('Docker compose is not installed')
183-
}
184-
containerNameSuffix = promiseSucceededIndex === 0 ? '_' : '-'
185-
return new DockerComposeEnvironment(
186-
path.join(pathToTestDataFolder),
187-
'docker-compose.yml'
188-
)
189-
.withEnvironment({ MYUID: os.userInfo().uid.toString() })
190-
.withWaitStrategy(
191-
`postgresql${containerNameSuffix}1`,
192-
Wait.forHealthCheck()
193-
)
194-
.withWaitStrategy(
195-
`synapse-federation${containerNameSuffix}1`,
196-
Wait.forHealthCheck()
197-
)
198-
.withWaitStrategy(
199-
`synapse-1${containerNameSuffix}1`,
200-
Wait.forHealthCheck()
201-
)
202-
.withWaitStrategy(
203-
`synapse-2${containerNameSuffix}1`,
204-
Wait.forHealthCheck()
205-
)
206-
.withWaitStrategy(
207-
`synapse-3${containerNameSuffix}1`,
208-
Wait.forHealthCheck()
209-
)
210-
.up()
211-
})
173+
new DockerComposeEnvironment(
174+
path.join(pathToTestDataFolder),
175+
'docker-compose.yml'
176+
)
177+
.withEnvironment({ MYUID: os.userInfo().uid.toString() })
178+
.withWaitStrategy('postgresql', Wait.forHealthCheck())
179+
.withWaitStrategy('synapse-federation', Wait.forHealthCheck())
180+
.withWaitStrategy('synapse-1', Wait.forHealthCheck())
181+
.withWaitStrategy('synapse-2', Wait.forHealthCheck())
182+
.withWaitStrategy('synapse-3', Wait.forHealthCheck())
183+
.up()
212184
// eslint-disable-next-line @typescript-eslint/promise-function-async
213185
.then((upResult) => {
214186
startedCompose = upResult
@@ -275,10 +247,10 @@ describe('Federation server', () => {
275247

276248
beforeAll((done) => {
277249
identity1IPAddress = startedCompose
278-
.getContainer(`identity-server-1${containerNameSuffix}1`)
250+
.getContainer(`identity-server-1`)
279251
.getIpAddress('test')
280252
identity2IPAddress = startedCompose
281-
.getContainer(`identity-server-2${containerNameSuffix}1`)
253+
.getContainer(`identity-server-2`)
282254
.getIpAddress('test')
283255

284256
confOriginalContent = fs.readFileSync(
@@ -295,9 +267,8 @@ describe('Federation server', () => {
295267
'utf-8'
296268
)
297269

298-
federationServerContainer = startedCompose.getContainer(
299-
`federation-server${containerNameSuffix}1`
300-
)
270+
federationServerContainer =
271+
startedCompose.getContainer('federation-server')
301272

302273
federationServerContainer
303274
.restart()
@@ -746,25 +717,19 @@ describe('Federation server', () => {
746717
'Certificates files for federation server has not been created'
747718
)
748719
return Promise.all([
749-
startedCompose
750-
.getContainer(`identity-server-1${containerNameSuffix}1`)
751-
.restart(),
752-
startedCompose
753-
.getContainer(`identity-server-2${containerNameSuffix}1`)
754-
.restart(),
755-
startedCompose
756-
.getContainer(`identity-server-3${containerNameSuffix}1`)
757-
.restart()
720+
startedCompose.getContainer('identity-server-1').restart(),
721+
startedCompose.getContainer('identity-server-2').restart(),
722+
startedCompose.getContainer('identity-server-3').restart()
758723
])
759724
})
760725
// eslint-disable-next-line @typescript-eslint/promise-function-async
761726
.then(() => {
762727
identity1IPAddress = startedCompose
763-
.getContainer(`identity-server-1${containerNameSuffix}1`)
728+
.getContainer(`identity-server-1`)
764729
.getIpAddress('test')
765730

766731
identity2IPAddress = startedCompose
767-
.getContainer(`identity-server-2${containerNameSuffix}1`)
732+
.getContainer(`identity-server-2`)
768733
.getIpAddress('test')
769734

770735
const testConfig: Config = {
@@ -776,16 +741,16 @@ describe('Federation server', () => {
776741
database_user: 'twake',
777742
database_password: 'twake!1',
778743
database_host: `${startedCompose
779-
.getContainer(`postgresql${containerNameSuffix}1`)
744+
.getContainer(`postgresql`)
780745
.getHost()}:5432`,
781746
database_name: 'federation',
782747
ldap_base: 'dc=example,dc=com',
783748
ldap_uri: `ldap://${startedCompose
784-
.getContainer(`postgresql${containerNameSuffix}1`)
749+
.getContainer(`postgresql`)
785750
.getHost()}:389`,
786751
matrix_database_engine: 'pg',
787752
matrix_database_host: `${startedCompose
788-
.getContainer(`postgresql${containerNameSuffix}1`)
753+
.getContainer(`postgresql`)
789754
.getHost()}:5432`,
790755
matrix_database_name: 'synapsefederation',
791756
matrix_database_user: 'synapse',

0 commit comments

Comments
 (0)