Merge branch 'v1.3'

This commit is contained in:
fit2-zhao 2020-10-12 09:43:54 +08:00
commit 9e154c6d87
2 changed files with 321 additions and 326 deletions

View File

@ -1071,11 +1071,8 @@ class JMXGenerator {
this.addScenarioHeaders(threadGroup, scenario); this.addScenarioHeaders(threadGroup, scenario);
this.addScenarioCookieManager(threadGroup, scenario); this.addScenarioCookieManager(threadGroup, scenario);
// 放在计划或线程组中,不建议放具体某个请求中
this.addDNSCacheManager(threadGroup, scenario);
this.addJDBCDataSources(threadGroup, scenario); this.addJDBCDataSources(threadGroup, scenario);
scenario.requests.forEach(request => { scenario.requests.forEach(request => {
if (request.enable) { if (request.enable) {
if (!request.isValid()) return; if (!request.isValid()) return;
@ -1095,6 +1092,8 @@ class JMXGenerator {
sampler = new TCPSampler(request.name || "", request); sampler = new TCPSampler(request.name || "", request);
} }
this.addDNSCacheManager(sampler, scenario.environment, request.useEnvironment);
this.addRequestExtractor(sampler, request); this.addRequestExtractor(sampler, request);
this.addRequestAssertion(sampler, request); this.addRequestAssertion(sampler, request);
@ -1156,18 +1155,14 @@ class JMXGenerator {
} }
} }
addDNSCacheManager(threadGroup, scenario) { addDNSCacheManager(httpSamplerProxy, environment, useEnv) {
if (scenario.requests.length < 1) { if (environment && useEnv === true) {
return let commonConfig = environment.config.commonConfig;
}
let request = scenario.requests[0];
if (request.environment) {
let commonConfig = request.environment.config.commonConfig;
let hosts = commonConfig.hosts; let hosts = commonConfig.hosts;
if (commonConfig.enableHost && hosts.length > 0) { if (commonConfig.enableHost && hosts.length > 0) {
let name = request.name + " DNSCacheManager"; let name = " DNSCacheManager";
// 强化判断如果未匹配到合适的host则不开启DNSCache // 强化判断如果未匹配到合适的host则不开启DNSCache
let domain = request.environment.config.httpConfig.domain; let domain = environment.config.httpConfig.domain;
let validHosts = []; let validHosts = [];
hosts.forEach(item => { hosts.forEach(item => {
if (item.domain != undefined && domain != undefined) { if (item.domain != undefined && domain != undefined) {
@ -1179,7 +1174,7 @@ class JMXGenerator {
} }
}); });
if (validHosts.length > 0) { if (validHosts.length > 0) {
threadGroup.put(new DNSCacheManager(name, validHosts)); httpSamplerProxy.put(new DNSCacheManager(name, validHosts));
} }
} }
} }