1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00
verdaccio/test/functional/performance/race.ts
Juan Picado @jotadeveloper 66f4197236
feat: convert project to typescript (#1374)
* chore: test

* chore: add

* chore: more progress

* chore: progress in migration, fix prettier parser

* chore: reduce tsc errors

* chore: refactor storage utils types

* chore: refactor utils types

* chore: refactor local storage types

* chore: refactor config utils types

* chore: refactor tsc types

* refactor: apply eslint fix, tabs etc

* chore: fix lint errors

* test: update unit test conf to typescript setup

few test refactored to typescript

* chore: enable more unit test

migrate to typescript

* chore: migrate storage test to tsc

* chore: migrate up storage test to tsc

* refactor: enable plugin and auth test

* chore: migrate plugin loader test

* chore: update dependencies

* chore: migrate functional test to typescript

* chore: add codecove

* chore: update express

* chore: downgrade puppeteer

The latest version does not seems to work properly fine.

* chore: update dependencies
2019-07-16 08:40:01 +02:00

130 lines
3.7 KiB
TypeScript

import async from 'async';
import { HTTP_STATUS } from "../../../src/lib/constants";
let okTotalSum = 0;
import racePkg from '../fixtures/package';
export default function(server) {
describe('should test race condition on publish packages', () => {
const MAX_COUNT = 20;
const PKG_NAME = 'race';
const PUBLISHED = 'published';
const PRESENT = 'already present';
const UNAVAILABLE = 'unavailable';
beforeAll(function () {
return server.putPackage(PKG_NAME, racePkg(PKG_NAME))
.status(HTTP_STATUS.CREATED)
.body_ok(/created new package/);
});
test('creating new package', () => {});
test('should uploading 10 same versions and ignore 9', callback => {
let listOfRequest = [];
for (let i = 0; i < MAX_COUNT; i++) {
// @ts-ignore
listOfRequest.push(function (callback) {
let data = racePkg(PKG_NAME);
data.rand = Math.random();
let _res;
server.putVersion(PKG_NAME, '0.0.1', data).response(function (res) {
_res = res;
}).then(function (body) {
callback(null, [_res, body]);
});
});
}
async.parallel(listOfRequest, function (err, response) {
let okCount = 0;
let failCount = 0;
expect(err).toBeNull();
// @ts-ignore
response.forEach(function (payload) {
// @ts-ignore
const [resp, body] = payload;
if (resp.statusCode === HTTP_STATUS.CREATED && ~body.ok.indexOf(PUBLISHED)) {
okCount++;
}
if (resp.statusCode === HTTP_STATUS.CONFLICT && ~body.error.indexOf(PRESENT)) {
failCount++;
}
if (resp.statusCode === HTTP_STATUS.SERVICE_UNAVAILABLE && ~body.error.indexOf(UNAVAILABLE)) {
failCount++;
}
});
expect(okCount + failCount).toEqual(MAX_COUNT);
expect(okCount).toEqual(1);
expect(failCount).toEqual(MAX_COUNT - 1);
okTotalSum += okCount;
callback();
});
});
test('shoul uploading 10 diff versions and accept 10', callback => {
const listofRequest = [];
for (let i = 0; i < MAX_COUNT; i++) {
// @ts-ignore
listofRequest.push(function (callback) {
let _res;
server.putVersion(PKG_NAME, '0.1.' + String(i), racePkg(PKG_NAME))
.response(function (res) {
_res = res;
})
.then(function (body) {
callback(null, [_res, body]);
});
});
}
async.parallel(listofRequest, function (err, response) {
let okcount = 0;
let failcount = 0;
expect(err).toBeNull();
// @ts-ignore
response.forEach(function (payload) {
// @ts-ignore
const [response, body] = payload;
if (response.statusCode === HTTP_STATUS.CREATED && ~body.ok.indexOf(PUBLISHED)) {
okcount++;
}
if (response.statusCode === HTTP_STATUS.CONFLICT && ~body.error.indexOf(PRESENT)) {
failcount++;
}
if (response.statusCode === HTTP_STATUS.SERVICE_UNAVAILABLE && ~body.error.indexOf(UNAVAILABLE)) {
failcount++;
}
});
expect(okcount + failcount).toEqual(MAX_COUNT);
expect(okcount).toEqual(MAX_COUNT);
expect(failcount).toEqual(0);
// should be more than 1
expect(okcount).not.toEqual(1);
okTotalSum += okcount;
callback();
});
});
afterAll(function() {
return server.getPackage(PKG_NAME).status(HTTP_STATUS.OK).then(function (body) {
expect(Object.keys(body.versions)).toHaveLength(okTotalSum);
});
});
});
}