fix(接口测试): 修复TCP接口测试超时时间不生效的问题

--bug=1008379 --user=宋天阳 【github#7974】tcp接口的请求时间和响应时间不起作用
https://www.tapd.cn/55049933/s/1113826
This commit is contained in:
song-tianyang 2022-03-04 14:29:54 +08:00 committed by CountryBuilder
parent e439c0b241
commit 463dfaa463
2 changed files with 64 additions and 22 deletions

View File

@ -227,7 +227,7 @@ public class MsTCPSampler extends MsTestElement {
} }
private void parseEnvironment(EnvironmentConfig config) { private void parseEnvironment(EnvironmentConfig config) {
if (!isCustomizeReq() && config != null) { if (!isCustomizeReq() && config != null && config.getTcpConfig() != null) {
if (!isCustomizeReq() && config != null) { if (!isCustomizeReq() && config != null) {
this.server = config.getTcpConfig().getServer(); this.server = config.getTcpConfig().getServer();
this.port = config.getTcpConfig().getPort(); this.port = config.getTcpConfig().getPort();
@ -238,6 +238,14 @@ public class MsTCPSampler extends MsTestElement {
this.eolByte = config.getTcpConfig().getEolByte(); this.eolByte = config.getTcpConfig().getEolByte();
} }
} }
if ((StringUtils.isEmpty(this.timeout) || StringUtils.equals(this.timeout, "0")) && StringUtils.isNotEmpty(config.getTcpConfig().getTimeout())) {
this.timeout = config.getTcpConfig().getTimeout();
}
if (StringUtils.isEmpty(this.ctimeout) || StringUtils.equals(this.ctimeout, "0") && StringUtils.isNotEmpty(config.getTcpConfig().getCtimeout())) {
this.ctimeout = config.getTcpConfig().getCtimeout();
}
} }
} }
} }
@ -265,6 +273,12 @@ public class MsTCPSampler extends MsTestElement {
tcpSampler.setCloseConnection(String.valueOf(this.isCloseConnection())); tcpSampler.setCloseConnection(String.valueOf(this.isCloseConnection()));
tcpSampler.setSoLinger(this.getSoLinger()); tcpSampler.setSoLinger(this.getSoLinger());
tcpSampler.setEolByte(this.getEolByte()); tcpSampler.setEolByte(this.getEolByte());
if (StringUtils.isNotEmpty(this.timeout)) {
tcpSampler.setTimeout(this.timeout);
}
if (StringUtils.isNotEmpty(this.ctimeout)) {
tcpSampler.setConnectTimeout(this.ctimeout);
}
String value = this.getRequest(); String value = this.getRequest();
if (StringUtils.isNotEmpty(this.getConnectEncoding())) { if (StringUtils.isNotEmpty(this.getConnectEncoding())) {

View File

@ -8,7 +8,7 @@
<el-input v-if="!apiCase.id || isShowInput" size="small" v-model="apiCase.name" :name="index" :key="index" <el-input v-if="!apiCase.id || isShowInput" size="small" v-model="apiCase.name" :name="index" :key="index"
class="ms-api-header-select" style="width: 180px" class="ms-api-header-select" style="width: 180px"
:readonly="!hasPermission('PROJECT_API_DEFINITION:READ+EDIT_CASE')" :readonly="!hasPermission('PROJECT_API_DEFINITION:READ+EDIT_CASE')"
:placeholder="$t('commons.input_name')" ref="nameEdit"/> :placeholder="$t('commons.input_name')" ref="nameEdit"/>
<span v-else> <span v-else>
<el-tooltip :content="apiCase.id ? apiCase.name : ''" placement="top"> <el-tooltip :content="apiCase.id ? apiCase.name : ''" placement="top">
<span>{{ apiCase.id ? apiCase.name : '' | ellipsis }}</span> <span>{{ apiCase.id ? apiCase.name : '' | ellipsis }}</span>
@ -17,7 +17,8 @@
<i class="el-icon-edit" style="cursor:pointer" @click="showInput(apiCase)"/> <i class="el-icon-edit" style="cursor:pointer" @click="showInput(apiCase)"/>
</span> </span>
<el-link type="primary" style="margin-left: 10px" @click="openHis(apiCase)" v-if="apiCase.id">{{ $t('operating_log.change_history') }}</el-link> <el-link type="primary" style="margin-left: 10px" @click="openHis(apiCase)"
v-if="apiCase.id">{{ $t('operating_log.change_history') }}</el-link>
</span> </span>
<div v-if="apiCase.id" style="color: #999999;font-size: 12px"> <div v-if="apiCase.id" style="color: #999999;font-size: 12px">
<span style="margin-left: 10px"> <span style="margin-left: 10px">
@ -27,13 +28,15 @@
</div> </div>
</el-col> </el-col>
<el-col :span="2"> <el-col :span="2">
<el-select size="mini" v-model="apiCase.priority" class="ms-api-select" @change="changePriority(apiCase)" :disabled="loaded"> <el-select size="mini" v-model="apiCase.priority" class="ms-api-select" @change="changePriority(apiCase)"
:disabled="loaded">
<el-option v-for="grd in priorities" :key="grd.id" :label="grd.name" :value="grd.id"/> <el-option v-for="grd in priorities" :key="grd.id" :label="grd.name" :value="grd.id"/>
</el-select> </el-select>
</el-col> </el-col>
<el-col :span="api.protocol==='HTTP'?4:0"> <el-col :span="api.protocol==='HTTP'?4:0">
<span v-if="api.protocol==='HTTP'"> <span v-if="api.protocol==='HTTP'">
<el-tag size="mini" :style="{'background-color': getColor(true, apiCase.request.method), border: getColor(true, apiCase.request.method)}" <el-tag size="mini"
:style="{'background-color': getColor(true, apiCase.request.method), border: getColor(true, apiCase.request.method)}"
class="api-el-tag"> class="api-el-tag">
{{ apiCase.request.method }} {{ apiCase.request.method }}
</el-tag> </el-tag>
@ -45,34 +48,42 @@
<el-col :span="5"> <el-col :span="5">
<el-row> <el-row>
<el-col :span="8"> <el-col :span="8">
<el-select size="small" v-model="apiCase.caseStatus" style="margin-right: 5px" @change="saveTestCase(apiCase,true)" :disabled="loaded"> <el-select size="small" v-model="apiCase.caseStatus" style="margin-right: 5px"
@change="saveTestCase(apiCase,true)" :disabled="loaded">
<el-option v-for="item in options" :key="item.id" :label="$t(item.label)" :value="item.id"/> <el-option v-for="item in options" :key="item.id" :label="$t(item.label)" :value="item.id"/>
</el-select> </el-select>
</el-col> </el-col>
<el-col :span="16"> <el-col :span="16">
<div class="tag-item" @click.stop> <div class="tag-item" @click.stop>
<el-tooltip :content="$t('commons.follow')" placement="bottom" effect="dark" v-if="!showFollow"> <el-tooltip :content="$t('commons.follow')" placement="bottom" effect="dark" v-if="!showFollow">
<i class="el-icon-star-off" style="color: #783987; font-size: 25px; margin-top: 2px; margin-right: 15px;cursor: pointer " @click="saveFollow"/> <i class="el-icon-star-off"
style="color: #783987; font-size: 25px; margin-top: 2px; margin-right: 15px;cursor: pointer "
@click="saveFollow"/>
</el-tooltip> </el-tooltip>
<el-tooltip :content="$t('commons.cancel')" placement="bottom" effect="dark" v-if="showFollow"> <el-tooltip :content="$t('commons.cancel')" placement="bottom" effect="dark" v-if="showFollow">
<i class="el-icon-star-on" style="color: #783987; font-size: 28px; margin-top: 2px; margin-right: 15px;cursor: pointer " @click="saveFollow" v-if="showFollow"/> <i class="el-icon-star-on"
style="color: #783987; font-size: 28px; margin-top: 2px; margin-right: 15px;cursor: pointer "
@click="saveFollow" v-if="showFollow"/>
</el-tooltip> </el-tooltip>
</div> </div>
</el-col> </el-col>
</el-row> </el-row>
<el-row style="margin-top: 5px"> <el-row style="margin-top: 5px">
<div class="tag-item" @click.stop> <div class="tag-item" @click.stop>
<ms-input-tag :currentScenario="apiCase" ref="tag" @keyup.enter.native="saveTestCase(apiCase,true)" :disabled="loaded"/> <ms-input-tag :currentScenario="apiCase" ref="tag" @keyup.enter.native="saveTestCase(apiCase,true)"
:disabled="loaded"/>
</div> </div>
</el-row> </el-row>
</el-col> </el-col>
<el-col :span="3"> <el-col :span="3">
<span @click.stop v-if="!loaded"> <span @click.stop v-if="!loaded">
<ms-tip-button @click="singleRun(apiCase)" :tip="$t('api_test.run')" icon="el-icon-video-play" v-permission="['PROJECT_API_DEFINITION:READ+RUN']" <ms-tip-button @click="singleRun(apiCase)" :tip="$t('api_test.run')" icon="el-icon-video-play"
v-permission="['PROJECT_API_DEFINITION:READ+RUN']"
class="run-button" size="mini" :disabled="!apiCase.id || loaded" circle v-if="!loading"/> class="run-button" size="mini" :disabled="!apiCase.id || loaded" circle v-if="!loading"/>
<el-tooltip :content="$t('report.stop_btn')" placement="top" :enterable="false" v-else> <el-tooltip :content="$t('report.stop_btn')" placement="top" :enterable="false" v-else>
<el-button :disabled="!apiCase.id" @click.once="stop(apiCase)" size="mini" style="color:white;padding: 0;width: 28px;height: 28px;" class="stop-btn" circle> <el-button :disabled="!apiCase.id" @click.once="stop(apiCase)" size="mini"
style="color:white;padding: 0;width: 28px;height: 28px;" class="stop-btn" circle>
<div style="transform: scale(0.72)"> <div style="transform: scale(0.72)">
<span style="margin-left: -3.5px;font-weight: bold">STOP</span> <span style="margin-left: -3.5px;font-weight: bold">STOP</span>
</div> </div>
@ -85,10 +96,12 @@
</el-col> </el-col>
<el-col :span="4"> <el-col :span="4">
<el-link @click.stop type="danger" v-if="apiCase.execResult && apiCase.execResult==='error'" @click="showExecResult(apiCase)"> <el-link @click.stop type="danger" v-if="apiCase.execResult && apiCase.execResult==='error'"
@click="showExecResult(apiCase)">
{{ getResult(apiCase.execResult) }} {{ getResult(apiCase.execResult) }}
</el-link> </el-link>
<el-link @click.stop v-else-if="apiCase.execResult && apiCase.execResult==='success'" @click="showExecResult(apiCase)"> <el-link @click.stop v-else-if="apiCase.execResult && apiCase.execResult==='success'"
@click="showExecResult(apiCase)">
{{ getResult(apiCase.execResult) }} {{ getResult(apiCase.execResult) }}
</el-link> </el-link>
<div v-else> {{ getResult(apiCase.execResult) }}</div> <div v-else> {{ getResult(apiCase.execResult) }}</div>
@ -110,22 +123,27 @@
<div v-if="apiCase.active||type==='detail'" v-loading="loading"> <div v-if="apiCase.active||type==='detail'" v-loading="loading">
<el-divider></el-divider> <el-divider></el-divider>
<p class="tip">{{ $t('api_test.definition.request.req_param') }} </p> <p class="tip">{{ $t('api_test.definition.request.req_param') }} </p>
<ms-api-request-form :isShowEnable="true" :showScript="true" :headers="apiCase.request.headers " :request="apiCase.request" v-if="api.protocol==='HTTP'"/> <ms-api-request-form :isShowEnable="true" :showScript="true" :headers="apiCase.request.headers "
<tcp-format-parameters :showScript="true" :request="apiCase.request" v-if="api.method==='TCP' && apiCase.request.esbDataStruct == null"/> :request="apiCase.request" v-if="api.protocol==='HTTP'"/>
<esb-definition v-xpack :request="apiCase.request" :showScript="true" v-if="isXpack&&api.method==='ESB'" ref="esbDefinition"/> <tcp-format-parameters :showScript="true" :request="apiCase.request" v-if="api.method==='TCP'"/>
<esb-definition v-xpack :request="apiCase.request" :showScript="true" v-if="isXpack&&api.method==='ESB'"
ref="esbDefinition"/>
<ms-sql-basis-parameters :showScript="true" :request="apiCase.request" v-if="api.protocol==='SQL'"/> <ms-sql-basis-parameters :showScript="true" :request="apiCase.request" v-if="api.protocol==='SQL'"/>
<ms-dubbo-basis-parameters :showScript="true" :request="apiCase.request" v-if="api.protocol==='DUBBO'"/> <ms-dubbo-basis-parameters :showScript="true" :request="apiCase.request" v-if="api.protocol==='DUBBO'"/>
<!-- HTTP 请求返回数据 --> <!-- HTTP 请求返回数据 -->
<p class="tip">{{ $t('api_test.definition.request.res_param') }}</p> <p class="tip">{{ $t('api_test.definition.request.res_param') }}</p>
<div v-if="isXpack&&api.method==='ESB'"> <div v-if="isXpack&&api.method==='ESB'">
<esb-definition-response v-xpack v-if="isXpack" :currentProtocol="apiCase.request.protocol" :request="apiCase.request" :is-api-component="false" :show-options-button="false" :show-header="true" :api-item="apiCase"/> <esb-definition-response v-xpack v-if="isXpack" :currentProtocol="apiCase.request.protocol"
:request="apiCase.request" :is-api-component="false" :show-options-button="false"
:show-header="true" :api-item="apiCase"/>
</div> </div>
<div v-else> <div v-else>
<api-response-component :currentProtocol="apiCase.request.protocol" :api-item="apiCase" :result="runResult"/> <api-response-component :currentProtocol="apiCase.request.protocol" :api-item="apiCase" :result="runResult"/>
</div> </div>
<ms-jmx-step v-if="apiCase.request.hashTree && apiCase.request.hashTree.length > 0" :request="apiCase.request" :api-id="api.id" :response="apiCase.responseData"/> <ms-jmx-step v-if="apiCase.request.hashTree && apiCase.request.hashTree.length > 0" :request="apiCase.request"
:api-id="api.id" :response="apiCase.responseData"/>
</div> </div>
</el-collapse-transition> </el-collapse-transition>
@ -192,7 +210,7 @@ export default {
ShowMoreBtn, ShowMoreBtn,
MsChangeHistory, MsChangeHistory,
"esbDefinition": esbDefinition.default, "esbDefinition": esbDefinition.default,
"esbDefinitionResponse": esbDefinitionResponse.default , "esbDefinitionResponse": esbDefinitionResponse.default,
ApiCaseHeader ApiCaseHeader
}, },
data() { data() {
@ -324,7 +342,14 @@ export default {
let uuid = getUUID(); let uuid = getUUID();
let request = JSON.parse(JSON.stringify(data.request)); let request = JSON.parse(JSON.stringify(data.request));
request.id = uuid; request.id = uuid;
let obj = {name: "copy_" + data.name, priority: data.priority, active: true, tags: data.tags, request: request, uuid: uuid}; let obj = {
name: "copy_" + data.name,
priority: data.priority,
active: true,
tags: data.tags,
request: request,
uuid: uuid
};
this.$emit('copyCase', obj); this.$emit('copyCase', obj);
} }
}, },
@ -394,7 +419,10 @@ export default {
stepArray[i].clazzName = TYPE_TO_C.get(stepArray[i].type); stepArray[i].clazzName = TYPE_TO_C.get(stepArray[i].type);
} }
if (stepArray[i].type === "Assertions" && !stepArray[i].document) { if (stepArray[i].type === "Assertions" && !stepArray[i].document) {
stepArray[i].document = {type: "JSON", data: {xmlFollowAPI: false, jsonFollowAPI: false, json: [], xml: []}}; stepArray[i].document = {
type: "JSON",
data: {xmlFollowAPI: false, jsonFollowAPI: false, json: [], xml: []}
};
} }
if (stepArray[i] && stepArray[i].authManager && !stepArray[i].authManager.clazzName) { if (stepArray[i] && stepArray[i].authManager && !stepArray[i].authManager.clazzName) {
stepArray[i].authManager.clazzName = TYPE_TO_C.get(stepArray[i].authManager.type); stepArray[i].authManager.clazzName = TYPE_TO_C.get(stepArray[i].authManager.type);
@ -479,7 +507,7 @@ export default {
this.addModule(row); this.addModule(row);
} else { } else {
this.api.source = "editCase"; this.api.source = "editCase";
if (!this.isSave){ if (!this.isSave) {
this.saveCase(row, hideAlert); this.saveCase(row, hideAlert);
} }
} }