Skip to content

Commit

Permalink
added concurrent request
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtcmn committed Apr 25, 2022
1 parent b9b8383 commit 7ffe847
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const CONFIG_PARAMS = {
"HEADERS": "headers",
"DATA": "data",
"SUCCESS_CHECKER_FN": "requestSuccessChecker",
"OTHER_AXIOS_REQUEST_CONFIGS": "requestConfig"
"OTHER_AXIOS_REQUEST_CONFIGS": "requestConfig",
"CONCURRENT_REQUEST": "concurrentRequest"
}


Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class HttpLoadTest {

this.TOTAL_REQUEST = 0;
this.PER_SECOND_REQUEST = 0;
this.CONCURRENT_REQUEST = 1;
this.AXIOS_REQUEST_CONFIG = {
method: 'get'
};
Expand Down Expand Up @@ -52,6 +53,7 @@ class HttpLoadTest {

this.TOTAL_REQUEST = _c[CONFIG_PARAMS.TOTAL_REQUEST] || 10;
this.PER_SECOND_REQUEST = _c[CONFIG_PARAMS.PER_SECOND_REQUEST] || 10;
this.CONCURRENT_REQUEST = _c[CONFIG_PARAMS.CONCURRENT_REQUEST] || 1;
this.stats.totalRequest = this.TOTAL_REQUEST;


Expand Down Expand Up @@ -143,7 +145,7 @@ class HttpLoadTest {


startTest() {
this.MAIN_JOB = new Array(this.TOTAL_REQUEST).fill(true).map((i, index) => this.oneJob(index));
this.MAIN_JOB = new Array(this.TOTAL_REQUEST).fill(true).map((i, index) => this.oneJob(Math.floor(index / this.CONCURRENT_REQUEST)));
Promise.all(this.MAIN_JOB).then((allRes) => {

this.onListener.emit('finished', this.stats);
Expand Down

0 comments on commit 7ffe847

Please sign in to comment.