refactor(性能测试): 优化性能测试本地调试体验
This commit is contained in:
parent
07f728f57a
commit
d0f622ab6f
|
@ -0,0 +1,41 @@
|
||||||
|
package io.metersphere.commons.utils;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.NetworkInterface;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class LocalAddressUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 这个过滤了 是回路的地址
|
||||||
|
*/
|
||||||
|
public static Map<String, String> getIpAddresses() {
|
||||||
|
Enumeration<NetworkInterface> netInterfaces;
|
||||||
|
Map<String, String> result = new HashMap<>();
|
||||||
|
try {
|
||||||
|
// 拿到所有网卡
|
||||||
|
netInterfaces = NetworkInterface.getNetworkInterfaces();
|
||||||
|
InetAddress ip;
|
||||||
|
// 遍历每个网卡,拿到ip
|
||||||
|
while (netInterfaces.hasMoreElements()) {
|
||||||
|
NetworkInterface ni = netInterfaces.nextElement();
|
||||||
|
Enumeration<InetAddress> addresses = ni.getInetAddresses();
|
||||||
|
while (addresses.hasMoreElements()) {
|
||||||
|
ip = addresses.nextElement();
|
||||||
|
if (!ip.isLoopbackAddress() && ip.getHostAddress().indexOf(':') == -1) {
|
||||||
|
result.put(ni.getName(), ip.getHostAddress());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getIpAddress(String name) {
|
||||||
|
return getIpAddresses().get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ import io.metersphere.commons.constants.ReportKeys;
|
||||||
import io.metersphere.commons.constants.ResourceStatusEnum;
|
import io.metersphere.commons.constants.ResourceStatusEnum;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||||
|
import io.metersphere.commons.utils.LocalAddressUtils;
|
||||||
import io.metersphere.commons.utils.UrlTestUtils;
|
import io.metersphere.commons.utils.UrlTestUtils;
|
||||||
import io.metersphere.config.KafkaProperties;
|
import io.metersphere.config.KafkaProperties;
|
||||||
import io.metersphere.controller.ResultHolder;
|
import io.metersphere.controller.ResultHolder;
|
||||||
|
@ -85,10 +86,14 @@ public class DockerTestEngine extends AbstractEngine {
|
||||||
if (baseInfo != null) {
|
if (baseInfo != null) {
|
||||||
metersphereUrl = baseInfo.getUrl();
|
metersphereUrl = baseInfo.getUrl();
|
||||||
}
|
}
|
||||||
|
// docker 不能从 localhost 中下载文件, 本地开发
|
||||||
|
if (StringUtils.contains(metersphereUrl, "http://localhost") ||
|
||||||
|
StringUtils.contains(metersphereUrl, "http://127.0.0.1")) {
|
||||||
|
metersphereUrl = "http://" + LocalAddressUtils.getIpAddress("en0") + ":8081";
|
||||||
|
}
|
||||||
|
|
||||||
String jmeterPingUrl = metersphereUrl + "/jmeter/ping"; // 检查下载地址是否正确
|
String jmeterPingUrl = metersphereUrl + "/jmeter/ping"; // 检查下载地址是否正确
|
||||||
// docker 不能从 localhost 中下载文件
|
if (!UrlTestUtils.testUrlWithTimeOut(jmeterPingUrl, 1000)) {
|
||||||
if (StringUtils.contains(metersphereUrl, "http://localhost")
|
|
||||||
|| !UrlTestUtils.testUrlWithTimeOut(jmeterPingUrl, 1000)) {
|
|
||||||
MSException.throwException(Translator.get("run_load_test_file_init_error"));
|
MSException.throwException(Translator.get("run_load_test_file_init_error"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit a99681fe94107d42ff340f4e8dcdca95195cf884
|
Subproject commit 8bd3730267a6c1b383a781b3c4ef8526e5414d82
|
Loading…
Reference in New Issue