fix(UI 自动化): cloud环境有时候刷不出来执行时间较长的报告

--bug=1014412 --user=张大海 【UI测试】github#13927,ui-场景执行关闭了性能测试模式,执行页面任务等很久就不出报告,查看任务中心实际已经执行完了 https://www.tapd.cn/55049933/s/1192594
This commit is contained in:
zhangdahai112 2022-06-30 16:04:51 +08:00 committed by zhangdahai112
parent 5ffdac5032
commit b85c3ebf7e
2 changed files with 40 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import io.metersphere.websocket.c.to.c.util.MsgDto;
import javax.websocket.RemoteEndpoint;
import javax.websocket.Session;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
public class WebSocketUtils {
@ -27,8 +28,8 @@ public class WebSocketUtils {
// 单用户推送
public static void sendMessageSingle(MsgDto dto) {
sendMessage(ONLINE_USER_SESSIONS.get(dto.getReportId()), dto.getContent());
sendMessage(ONLINE_USER_SESSIONS.get(dto.getToReport()), dto.getContent());
sendMessage(ONLINE_USER_SESSIONS.get(Optional.ofNullable(dto.getReportId()).orElse("")), dto.getContent());
sendMessage(ONLINE_USER_SESSIONS.get(Optional.ofNullable(dto.getToReport()).orElse("")), dto.getContent());
}
// 全用户推送

View File

@ -151,7 +151,11 @@ export default {
infoDb: Boolean,
debug: Boolean,
scenario: {},
scenarioId: String
scenarioId: String,
isUi: {
type: Boolean,
default: false
}
},
methods: {
initTree() {
@ -300,7 +304,12 @@ export default {
}
const uri = protocol + window.location.host + "/ws/" + this.reportId;
this.messageWebSocket = new WebSocket(uri);
// ui使 ws
if (this.isUi) {
this.initHeartBeat();
}
this.messageWebSocket.onmessage = this.onMessage;
this.messageWebSocket.onerror = this.cleanHeartBeat;
},
getReport() {
let url = "/api/scenario/report/get/" + this.reportId;
@ -458,6 +467,7 @@ export default {
if (e.data && e.data.indexOf("MS_TEST_END") !== -1) {
this.getReport();
this.messageWebSocket.close();
this.cleanHeartBeat();
this.$EventBus.$emit('hide', this.scenarioId);
this.$emit('refresh', this.debugResult);
}
@ -490,6 +500,32 @@ export default {
}
}
}
},
websocketKey(){
return "ui_ws_" + this.reportId;
},
initHeartBeat() {
if (!window.localStorage.getItem(this.websocketKey())) {
window.localStorage.setItem(this.websocketKey(), this.reportId);
window.heartBeatHandle = setInterval(this.heartBeat, 30000);
} else {
this.cleanHeartBeat();
this.initHeartBeat();
}
},
cleanHeartBeat() {
if (window.heartBeatHandle) {
clearInterval(window.heartBeatHandle);
if (window.localStorage.getItem(this.websocketKey()))
window.localStorage.removeItem(this.websocketKey());
}
},
heartBeat() {
let msg = {
reportId: this.reportId,
content: "i'm alive"
};
this.messageWebSocket.send(JSON.stringify(msg));
}
},
computed: {