Merge pull request #95 from overleaf/jpa-test-cleanup

[misc] test cleanup
This commit is contained in:
Simon Detheridge 2020-03-04 10:01:39 +00:00 committed by GitHub
commit 8905d393f7
6 changed files with 44 additions and 26 deletions

View file

@ -4,11 +4,7 @@ const fs = require('fs')
const Path = require('path')
const { promisify } = require('util')
const disrequire = require('disrequire')
const rp = require('request-promise-native').defaults({
resolveWithFullResponse: true
})
const S3_TRIES = 30
const AWS = require('aws-sdk')
logger.logger.level('info')
@ -66,6 +62,7 @@ class FilestoreApp {
}
async stop() {
if (!this.server) return
const closeServer = promisify(this.server.close).bind(this.server)
try {
await closeServer()
@ -80,21 +77,31 @@ class FilestoreApp {
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 {
const response = await rp.get(`${Settings.filestore.s3.endpoint}/`)
if ([200, 404].includes(response.statusCode)) {
s3Available = true
}
return await s3
.putObject({
Key: 'startup',
Body: '42',
Bucket: Settings.filestore.stores.user_files
})
.promise()
} catch (err) {
// swallow errors, as we may experience them until fake-s3 is running
} finally {
tries++
if (!s3Available) {
await sleep(1000)
if (tries === 9) {
// throw just before hitting the 10s test timeout
throw err
}
tries++
await sleep(1000)
}
}
}

View file

@ -148,12 +148,8 @@ describe('Filestore', function() {
})
beforeEach(async function() {
// retrieve previous metrics from the app
if (Settings.filestore.backend === 's3') {
;[previousEgress, previousIngress] = await Promise.all([
getMetric(filestoreUrl, 's3_egress'),
getMetric(filestoreUrl, 's3_ingress')
])
previousEgress = await getMetric(filestoreUrl, 's3_egress')
}
projectId = `acceptance_tests_${Math.random()}`
})
@ -195,6 +191,15 @@ describe('Filestore', function() {
await pipeline(readStream, writeStream, resultStream)
})
beforeEach(async function retrievePreviousIngressMetrics() {
// The upload request can bump the ingress metric.
// The content hash validation might require a full download
// in case the ETag field of the upload response is not a md5 sum.
if (Settings.filestore.backend === 's3') {
previousIngress = await getMetric(filestoreUrl, 's3_ingress')
}
})
it('should return 404 for a non-existant id', async function() {
const options = { uri: fileUrl + '___this_is_clearly_wrong___' }
await expect(
@ -415,8 +420,8 @@ describe('Filestore', function() {
const s3ClientSettings = {
credentials: {
accessKeyId: 'fake',
secretAccessKey: 'fake'
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
},
endpoint: process.env.AWS_S3_ENDPOINT,
sslEnabled: false,

View file

@ -19,7 +19,10 @@ describe('ImageOptimiser', function() {
ImageOptimiser = SandboxedModule.require(modulePath, {
requires: {
'./SafeExec': SafeExec,
'logger-sharelatex': logger
'logger-sharelatex': logger,
'metrics-sharelatex': {
Timer: sinon.stub().returns({ done: sinon.stub() })
}
}
})
})

View file

@ -2,12 +2,14 @@ const SandboxedModule = require('sandboxed-module')
const modulePath = '../../../app/js/KeyBuilder.js'
describe('LocalFileWriter', function() {
describe('KeybuilderTests', function() {
let KeyBuilder
const key = 'wombat/potato'
beforeEach(function() {
KeyBuilder = SandboxedModule.require(modulePath)
KeyBuilder = SandboxedModule.require(modulePath, {
requires: { 'settings-sharelatex': {} }
})
})
describe('cachedKey', function() {

View file

@ -158,7 +158,7 @@ describe('S3PersistorTests', function() {
'metrics-sharelatex': Metrics,
crypto
},
globals: { console }
globals: { console, Buffer }
})
})

View file

@ -12,6 +12,7 @@ describe('SafeExec', function() {
options = { timeout: 10 * 1000, killSignal: 'SIGTERM' }
safeExec = SandboxedModule.require(modulePath, {
globals: { process },
requires: {
'settings-sharelatex': settings
}