Skip to content

Commit bc6d547

Browse files
tests(feathers-distributed): use different port for test servers
1 parent d78570e commit bc6d547

3 files changed

Lines changed: 19 additions & 15 deletions

File tree

packages/feathers-distributed/test/failures.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { beforeAll, afterAll, describe, it, expect, assert } from 'vitest'
55
import { createApp, waitForService, clone } from './utils.js'
66
import plugin, { finalize } from '../src/index.js'
77

8+
const baseListenPort = 3060
89
const startId = 2
910
const store = {
1011
0: { content: 'message 0', id: 0 },
@@ -58,7 +59,7 @@ describe('feathers-distributed:network', () => {
5859
// Now all services are registered setup handlers
5960
apps[i].use(express.notFound())
6061
apps[i].use(express.errorHandler())
61-
servers.push(await apps[i].listen(3030 + i))
62+
servers.push(await apps[i].listen(baseListenPort + i))
6263
}
6364
})
6465

packages/feathers-distributed/test/index.test.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class CustomMemoryService extends MemoryService {
1818
custom (data, params) { return data.name }
1919
}
2020

21+
const baseListenPort = 3050
2122
let startId = 6
2223
const authUser = {
2324
name: 'Jane Doe',
@@ -142,14 +143,14 @@ describe('feathers-distributed:main', () => {
142143
// Now all services are registered setup handlers
143144
apps[i].use(express.notFound())
144145
apps[i].use(express.errorHandler())
145-
servers.push(await apps[i].listen(3030 + i))
146+
servers.push(await apps[i].listen(baseListenPort + i))
146147
}
147148

148149
for (let i = 0; i < nbApps; i++) {
149150
appServices.push(apps[i].service('users'))
150151
assert.exists(appServices[i])
151152

152-
const url = 'http://localhost:' + (3030 + i)
153+
const url = 'http://localhost:' + (baseListenPort + i)
153154
const restTransporter = restClient(url).superagent(request)
154155
const rClient = feathers()
155156
.configure(restTransporter)
@@ -208,27 +209,27 @@ describe('feathers-distributed:main', () => {
208209

209210
it('ensure healthcheck can been called on apps', async () => {
210211
// Service 1 & 2 should see the gateway 0
211-
let url = 'http://localhost:' + (3030 + service1) + '/distribution/healthcheck/0'
212+
let url = 'http://localhost:' + (baseListenPort + service1) + '/distribution/healthcheck/0'
212213
let response = await request.get(url)
213214
expect(response.body).to.deep.equal({ users: true })
214-
url = 'http://localhost:' + (3030 + service2) + '/distribution/healthcheck/0'
215+
url = 'http://localhost:' + (baseListenPort + service2) + '/distribution/healthcheck/0'
215216
response = await request.get(url)
216217
expect(response.body).to.deep.equal({ users: true })
217218
// Gateway should see the no-events app 3
218-
url = 'http://localhost:' + (3030 + gateway) + '/distribution/healthcheck/3'
219+
url = 'http://localhost:' + (baseListenPort + gateway) + '/distribution/healthcheck/3'
219220
response = await request.get(url)
220221
expect(response.body).to.deep.equal({ 'no-events': true })
221222
// Listing all gateway services should be the same
222-
url = 'http://localhost:' + (3030 + gateway) + '/distribution/healthcheck/0'
223+
url = 'http://localhost:' + (baseListenPort + gateway) + '/distribution/healthcheck/0'
223224
response = await request.get(url)
224225
expect(response.body).to.deep.equal({ 'no-events': true })
225-
url = 'http://localhost:' + (3030 + gateway) + '/distribution/healthcheck'
226+
url = 'http://localhost:' + (baseListenPort + gateway) + '/distribution/healthcheck'
226227
response = await request.get(url)
227228
expect(response.body).to.deep.equal({ 'no-events': true })
228229
})
229230

230231
it('ensure middleware can been called on app', async () => {
231-
const url = 'http://localhost:' + (3030 + gateway) + '/middleware'
232+
const url = 'http://localhost:' + (baseListenPort + gateway) + '/middleware'
232233
await request.get(url)
233234
expect(appMiddleware).toHaveBeenCalled()
234235
})
@@ -273,7 +274,7 @@ describe('feathers-distributed:main', () => {
273274
}, 5000)
274275

275276
it('ensure middleware can been called on local service', async () => {
276-
const url = 'http://localhost:' + (3030 + gateway) + '/users'
277+
const url = 'http://localhost:' + (baseListenPort + gateway) + '/users'
277278
await request.get(url)
278279
expect(serviceMiddleware).toHaveBeenCalled()
279280
}, 5000)
@@ -543,7 +544,7 @@ describe('feathers-distributed:main', () => {
543544
.timeout(40000) */
544545

545546
it('not found request should return 404 on local service', async () => {
546-
const url = 'http://localhost:' + (3030 + gateway) + '/xxx'
547+
const url = 'http://localhost:' + (baseListenPort + gateway) + '/xxx'
547548
try {
548549
await request.get(url)
549550
} catch (err) {
@@ -554,7 +555,7 @@ describe('feathers-distributed:main', () => {
554555
}, 5000)
555556

556557
it('not found request should return 404 on remote service', async () => {
557-
const url = 'http://localhost:' + (3030 + service1) + '/xxx'
558+
const url = 'http://localhost:' + (baseListenPort + service1) + '/xxx'
558559
try {
559560
await request.get(url)
560561
} catch (err) {
@@ -575,7 +576,7 @@ describe('feathers-distributed:main', () => {
575576
}, 5000)
576577

577578
it('unauthenticated request should return 401 on local service with auth', async () => {
578-
const url = 'http://localhost:' + (3030 + gateway) + '/users'
579+
const url = 'http://localhost:' + (baseListenPort + gateway) + '/users'
579580
try {
580581
await request.get(url)
581582
} catch (err) {
@@ -595,7 +596,7 @@ describe('feathers-distributed:main', () => {
595596
}, 5000)
596597

597598
it('unauthenticated request should return 401 on remote service with auth', async () => {
598-
const url = 'http://localhost:' + (3030 + service1) + '/users'
599+
const url = 'http://localhost:' + (baseListenPort + service1) + '/users'
599600
try {
600601
await request.get(url)
601602
} catch (err) {

packages/feathers-distributed/vitest.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export default mergeConfig(baseConfig, defineConfig({
1313
// beforeAll hook needs a lot of time to setup cote and stuff
1414
hookTimeout: 30000,
1515
// testTimeout: 30000,
16-
// Disable parallelism because different test files startup listening servers on same ports
16+
// Disable parallelism because tests fail otherwise, not sure exactly why.
17+
// Different files don't share same server ports, but touching the basePort in cote config seems
18+
// to break tests in index.test.js ... So currently files share the same cote basePort value.
1719
fileParallelism: false
1820
}
1921
}))

0 commit comments

Comments
 (0)