diff --git a/constant.js b/constant.js index a127d13..e5e7e8f 100644 --- a/constant.js +++ b/constant.js @@ -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" } diff --git a/index.js b/index.js index 46697d8..e03dced 100644 --- a/index.js +++ b/index.js @@ -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' }; @@ -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; @@ -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);