Skip to content

Commit

Permalink
Removed index on object.bucketId; tidy up K6 code
Browse files Browse the repository at this point in the history
  • Loading branch information
TimCsaky committed Apr 21, 2023
1 parent f26efef commit 67a14e3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,11 @@ exports.up = function (knex) {
.then(() => knex.schema.alterTable('object_permission', table => {
table.uuid('objectId').index().notNullable().alter();
table.uuid('userId').index().notNullable().alter();
}))
// Add index to object.bucketId
.then(() => knex.schema.alterTable('object', table => {
table.uuid('bucketId').index().alter();
}));
};

exports.down = function (knex) {
return Promise.resolve()
// Remove index on object.bucketId
.then(() => knex.schema.alterTable('object', table => {
table.dropIndex('bucketId');
}))
// Remove index on object_permission.userId and object_permission.objectId
.then(() => knex.schema.alterTable('object_permission', table => {
table.dropIndex('userId');
Expand Down
25 changes: 10 additions & 15 deletions app/tests/k6/createObject.js → k6/createObject.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import http from 'k6/http';
import { check, sleep } from 'k6';

// multipart file uploads - https://k6.io/docs/examples/data-uploads/#multipart-request-uploading-a-file

// k6 options (https://k6.io/docs/using-k6/k6-options/)
export const options = {
scenarios: {
createObject: {
executor: 'constant-arrival-rate',
rate: 20, // this is per-second, see "timeUnit" below
rate: 5, // this is per-second, see "timeUnit" below
timeUnit: '1s',
preAllocatedVUs: 1,
maxVUs: 1,
Expand All @@ -17,36 +15,33 @@ export const options = {
},
};

// give objects random tags
const apiPath = 'http://localhost:3000/api/v1';
const randomLetter = String.fromCharCode(65 + Math.floor(Math.random() * 26));
const bucketId = '<bucket ID (uuid)>';
const url = `${apiPath}/object?bucketId=${bucketId}&tagset[${randomLetter}]=${randomLetter}`;

// request url
const url = 'http://localhost:3000/api/v1/object?tagset[' + randomLetter + ']=' + randomLetter;

// open() the file as binary (with the 'b' argument).
// open() the file as binary (with the 'b' argument, must be declared in init scope)
// ref: https://k6.io/docs/examples/data-uploads/#multipart-request-uploading-a-file
// eslint-disable-next-line
const binFile = open('./file-in-cur-dir.txt', 'b');

// run k6
export default function () {
const data = {
// attach file, specify file name and content type
file: http.file(binFile, 'name-given-to-file.txt', 'text/plain'),
field: 'another form field'
file: http.file(binFile, 'abc.txt', 'text/plain')
};

// make the http request
const res = http.post(url, data, {
// add headers
headers: {
'Authorization': 'Bearer <user ID token here>'
'Authorization': 'Bearer <user ID token>'
}
});

// tests
check(res, {
'is status 201': (r) => r.status === 201,
})

});
// optional delay (per VU) between iterations
sleep(1);
}
9 changes: 5 additions & 4 deletions app/tests/k6/readObject.js → k6/readObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const options = {
scenarios: {
readObject: {
executor: 'constant-arrival-rate',
rate: 50,
rate: 20,
duration: '20s',
preAllocatedVUs: 50,
timeUnit: '1s',
Expand All @@ -19,8 +19,10 @@ export const options = {
// run k6
export default function () {

const apiPath = 'http://localhost:3000/api/v1';
// request url
const url = 'http://localhost:3000/api/v1/object/<object id here>';
const url = `${apiPath}/object/<object id here>`;

const params = {
headers: {
'Authorization': 'Bearer <token here>',
Expand All @@ -33,8 +35,7 @@ export default function () {
// tests
check(res, {
'is status 200': (r) => r.status === 200,
})

});
// optional delay (per VU) between iterations
sleep(1);
}
8 changes: 4 additions & 4 deletions app/tests/k6/searchObject.js → k6/searchObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ export const options = {

export default function () {

// search by random tags
const apiPath = 'http://localhost:3000/api/v1';
const randomLetter = String.fromCharCode(65 + Math.floor(Math.random() * 26));
const bucketId = '<bucket ID (uuid)>';

// request url
const url = 'http://localhost:3000/api/v1/object?latest=true&deleteMarker=false&tagset[' + randomLetter + ']=' + randomLetter;
const url = `${apiPath}/object?bucketId=${bucketId}&latest=true&deleteMarker=false&tagset[${randomLetter}]=${randomLetter}`;

// Add Authorization header
const params = {
Expand All @@ -32,8 +33,7 @@ export default function () {
// tests
check(res, {
'is status 200': (r) => r.status === 200,
})

});
// optional delay (per VU) between iterations
sleep(1);
}

0 comments on commit 67a14e3

Please sign in to comment.