Skip to content

Commit

Permalink
fix: await delay in tests. Handle write error.
Browse files Browse the repository at this point in the history
- the test occasionally fail in ci as we're not giving the app
time to update the config
- add a try/catch around the write conf, because you never know.

License: MIT
Signed-off-by: Oli Evans <oli@tableflip.io>
  • Loading branch information
olizilla committed May 24, 2019
1 parent b9eb179 commit 53b93a5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/utils/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,14 @@ function checkCorsConfig (ipfsd) {
if (allowedOrigins.some(origin => originsToRemove.includes(origin))) {
const specificOrigins = allowedOrigins.filter(origin => !originsToRemove.includes(origin))
config.API.HTTPHeaders['Access-Control-Allow-Origin'] = specificOrigins
writeConfigFile(ipfsd, config)
store.set('updatedCorsConfig', Date.now())
try {
writeConfigFile(ipfsd, config)
store.set('updatedCorsConfig', Date.now())
} catch (err) {
logger.error(`[daemon] checkCorsConfig: error writing config file: ${err.message || err}`)
// dont skip setting checkedCorsConfig so we try again next time time.
return
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('Application launch', function () {

const { app } = await startApp({ ipfsPath: repoPath })
expect(app.isRunning()).to.be.true()
delay(5000)
await delay(5000)
config = fs.readJsonSync(configPath)
// ensure app has enabled cors checking
expect(config.API.HTTPHeaders['Access-Control-Allow-Origin']).to.deep.equal([])
Expand Down Expand Up @@ -118,7 +118,7 @@ describe('Application launch', function () {

const { app } = await startApp({ ipfsPath: repoPath })
expect(app.isRunning()).to.be.true()
delay(5000)
await delay(5000)
const config = fs.readJsonSync(configPath)
// ensure app has enabled cors checking
const specificOrigins = newOrigins.filter(origin => origin !== '*')
Expand Down

0 comments on commit 53b93a5

Please sign in to comment.