[misc] test/acceptance: harden the startup check for s3

Signed-off-by: Jakob Ackermann <das7pad@outlook.com>
This commit is contained in:
Jakob Ackermann 2020-02-23 18:25:39 +00:00
parent 94b8a7f891
commit 6589aa6ae0

View file

@ -4,11 +4,7 @@ const fs = require('fs')
const Path = require('path') const Path = require('path')
const { promisify } = require('util') const { promisify } = require('util')
const disrequire = require('disrequire') const disrequire = require('disrequire')
const rp = require('request-promise-native').defaults({ const AWS = require('aws-sdk')
resolveWithFullResponse: true
})
const S3_TRIES = 30
logger.logger.level('info') logger.logger.level('info')
@ -80,21 +76,31 @@ class FilestoreApp {
return return
} }
let s3Available = false const s3 = new AWS.S3({
accessKeyId: Settings.filestore.s3.key,
secretAccessKey: Settings.filestore.s3.secret,
endpoint: Settings.filestore.s3.endpoint,
s3ForcePathStyle: true,
signatureVersion: 'v4'
})
while (tries < S3_TRIES && !s3Available) { while (true) {
try { try {
const response = await rp.get(`${Settings.filestore.s3.endpoint}/`) return await s3
if ([200, 404].includes(response.statusCode)) { .putObject({
s3Available = true Key: 'startup',
} Body: '42',
Bucket: Settings.filestore.stores.user_files
})
.promise()
} catch (err) { } catch (err) {
// swallow errors, as we may experience them until fake-s3 is running // swallow errors, as we may experience them until fake-s3 is running
} finally { if (tries === 9) {
tries++ // throw just before hitting the 10s test timeout
if (!s3Available) { throw err
await sleep(1000)
} }
tries++
await sleep(1000)
} }
} }
} }