Files
directus/tests-blackbox/routes/assets/limit.test.ts
Rijk van Zanten 9526b4e5b2 Improve S3 asset read performance (#17835)
* Create new s3 client for each read

* Temp disable ts while debugging

* Add concurrency test

* Add minio to other tests

* Reduce unavailable count

* Trigger blackbox tests whenever packages are updated

* Prevent minio-mc from exiting

* Decrease requests and increase test timeout

* Spam more requests over longer period

* Increase request timeout

* Run autocannon directly with larger image

* Fix tests

* Lock version

* My favorite file

---------

Co-authored-by: ian <licitdev@gmail.com>
2023-03-20 18:16:30 -04:00

96 lines
2.8 KiB
TypeScript

import config, { getUrl } from '@common/config';
import request from 'supertest';
import vendors from '@common/get-dbs-to-test';
import { createReadStream } from 'fs';
import path from 'path';
import * as common from '@common/index';
const assetsDirectory = [__dirname, '..', '..', 'assets'];
const storages = ['local', 'minio'];
const imageFile = {
name: 'directus.png',
type: 'image/png',
filesize: '7136',
};
const imageFilePath = path.join(...assetsDirectory, imageFile.name);
describe('/assets', () => {
describe('GET /assets/:id', () => {
describe('ASSETS_TRANSFORM_MAX_CONCURRENT Tests', () => {
describe('passes when below limit', () => {
describe.each(storages)('Storage: %s', (storage) => {
it.each(vendors)(
'%s',
async (vendor) => {
// Setup
const count = Number(config.envs[vendor].ASSETS_TRANSFORM_MAX_CONCURRENT);
const uploadedFileID = (
await request(getUrl(vendor))
.post('/files')
.set('Authorization', `Bearer ${common.USER.ADMIN.TOKEN}`)
.field('storage', storage)
.attach('file', createReadStream(imageFilePath))
).body.data.id;
// Action
const responses = await Promise.all(
Array(count)
.fill(0)
.map((_, index) =>
request(getUrl(vendor))
.get(`/assets/${uploadedFileID}?width=${4000 + index}&height=${4000 + index}`)
.set('Authorization', `Bearer ${common.USER.ADMIN.TOKEN}`)
)
);
// Assert
for (const response of responses) {
expect(response.statusCode).toBe(200);
}
},
60000
);
});
});
describe('errors when above limit', () => {
describe.each(storages)('Storage: %s', (storage) => {
it.each(vendors)(
'%s',
async (vendor) => {
// Setup
const attempts = 100;
const uploadedFileID = (
await request(getUrl(vendor))
.post('/files')
.set('Authorization', `Bearer ${common.USER.ADMIN.TOKEN}`)
.field('storage', storage)
.attach('file', createReadStream(imageFilePath))
).body.data.id;
// Action
const responses = await Promise.all(
Array(attempts)
.fill(0)
.map((_, index) =>
request(getUrl(vendor))
.get(`/assets/${uploadedFileID}?width=${4000 + index}&height=${4000 + index}`)
.set('Authorization', `Bearer ${common.USER.ADMIN.TOKEN}`)
)
);
// Assert
const unavailableCount = responses.filter((response) => response.statusCode === 503).length;
expect(unavailableCount).toBeGreaterThanOrEqual(1);
expect(responses.filter((response) => response.statusCode === 200).length).toBe(
attempts - unavailableCount
);
},
1200000
);
});
});
});
});
});