Skip to content

Commit dc8b598

Browse files
committed
Fix CI race in account creation tests
1 parent 2caddca commit dc8b598

2 files changed

Lines changed: 31 additions & 20 deletions

File tree

lib/create-server.mjs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,32 @@ function createServer (argv, app) {
103103
// Wrap server.listen() to ensure async initialization completes after server starts
104104
const originalListen = server.listen.bind(server)
105105
server.listen = function (...args) {
106-
// Start listening first
107-
originalListen(...args)
106+
const lastArg = args[args.length - 1]
107+
const hasCallback = typeof lastArg === 'function'
108+
const readyCallback = hasCallback ? lastArg : null
108109

109-
// Then run async initialization (if needed)
110-
if (ldpApp.locals.initFunction) {
110+
if (hasCallback) {
111+
args = args.slice(0, -1)
112+
}
113+
114+
originalListen(...args, () => {
111115
const initFunction = ldpApp.locals.initFunction
112116
delete ldpApp.locals.initFunction
113117

114-
// Run initialization after server is listening
118+
if (!initFunction) {
119+
if (readyCallback) readyCallback()
120+
return
121+
}
122+
115123
initFunction()
124+
.then(() => {
125+
if (readyCallback) readyCallback()
126+
})
116127
.catch(err => {
117128
console.error('Initialization error:', err)
118129
server.emit('error', err)
119130
})
120-
}
131+
})
121132

122133
return server
123134
}

test/integration/www-account-creation-oidc-test.mjs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,13 @@ describe('AccountManager (OIDC account creation tests)', function () {
227227
})
228228

229229
// FIXME: #1502
230-
describe('Single User signup page', () => {
231-
const serverUri = 'https://localhost:7457'
232-
const port = 7457
233-
let ldpHttpsServer
234-
rm('resources/accounts/single-user/')
235-
const rootDir = path.normalize(path.join(__dirname, '../resources/accounts/single-user/'))
236-
const configPath = path.normalize(path.join(__dirname, '../resources/config'))
237-
const ldp = ldnode.createServer({
230+
describe('Single User signup page', () => {
231+
const serverUri = 'https://localhost:7457'
232+
const port = 7457
233+
let ldpHttpsServer
234+
const rootDir = path.normalize(path.join(__dirname, '../resources/accounts/single-user/'))
235+
const configPath = path.normalize(path.join(__dirname, '../resources/config'))
236+
const ldp = ldnode.createServer({
238237
port,
239238
root: rootDir,
240239
configPath,
@@ -244,12 +243,13 @@ describe('Single User signup page', () => {
244243
multiuser: false,
245244
strictOrigin: true
246245
})
247-
const server = supertest(serverUri)
248-
249-
before(function (done) {
250-
ldpHttpsServer = ldp.listen(port, () => server.post('/api/accounts/new')
251-
.send('username=foo&password=12345&acceptToc=true')
252-
.end(done))
246+
const server = supertest(serverUri)
247+
248+
before(function (done) {
249+
fs.removeSync(rootDir)
250+
ldpHttpsServer = ldp.listen(port, () => server.post('/api/accounts/new')
251+
.send('username=foo&password=12345&acceptToc=true')
252+
.end(done))
253253
})
254254

255255
after(function () {

0 commit comments

Comments
 (0)