fix:执行引擎

1.前端当前步骤标识丢失,大概原因是在短时间后接收到多个回放指令replay_start,前端只记录最后的requestId作为标识,而引擎接受到多次replay_start需要按顺序处理多个回放。
引擎在响应最先接受到回放指令中requestId与前端不一致,那么前端无法显示步骤所有返回来的rely指令。
按照这样的逻辑,如果短时间内接收到多个replay_start回放指令,使用最后的requestId更新到正在回放的requestId。
hz_1122_temp
李杰应 2024-12-02 03:09:06 +08:00
parent a5cd812519
commit 1065c305d2
5 changed files with 130 additions and 2 deletions

View File

@ -30,6 +30,29 @@ public interface DebugSession extends Runnable {
*/
String getDeviceId();
/**
*
* @return
*/
boolean isReplay();
/**
* requestId
* @return
*/
String getRequestId();
/**
* requestId
* @param requestId
*/
void setRequestId(String requestId);
/**
* requestId
*/
void updateRequestId();
/**
*
* @param request

View File

@ -41,7 +41,10 @@ public class DefaultDebugSession implements DebugSession {
private String deviceId;
private DeviceConnection deviceConnection;
private String requestId;
private boolean running = true;
private boolean replaying = false;
private Thread thread;
@ -79,6 +82,9 @@ public class DefaultDebugSession implements DebugSession {
if (childResult != null) {
result.setChildResult(null); // 调试过程中子步骤的结果对于前端没有意义
}
if (requestId != null && !requestId.equalsIgnoreCase(result.getRequestId())) { // 请求标识requestId被修改了使用新的
result.setRequestId(requestId);
}
HashMap<String, Object> replyMap = new HashMap<>();
replyMap.put("cmd", DebugerConst.ReplyConst.KEY_CMD_REPLY);
replyMap.put(DebugerConst.KEY_SESSIONID, sessionId);
@ -96,6 +102,13 @@ public class DefaultDebugSession implements DebugSession {
HashMap<String, Object> replyMap = new HashMap<>();
replyMap.put("cmd", cmd);
replyMap.put(DebugerConst.KEY_SESSIONID, sessionId);
if (obj instanceof Map) {
Object mapRequestId = ((Map) obj).get(DebugerConst.KEY_REQUESTID);
if (requestId != null && !requestId.equalsIgnoreCase((String)mapRequestId)) { // 请求标识requestId被修改了使用新的
((Map) obj).put(DebugerConst.KEY_REQUESTID, requestId);
}
}
replyMap.put(DebugerConst.ReplyConst.KEY_REPLY_DATA, obj);
sendText(JsonUtils.toJson(replyMap));
}
@ -159,6 +172,48 @@ public class DefaultDebugSession implements DebugSession {
return this.deviceId;
}
/**
*
*
* @return
*/
@Override
public boolean isReplay() {
return this.replaying;
}
/**
* requestId
*
* @return
*/
@Override
public String getRequestId() {
return this.requestId;
}
/**
* requestId
*
* @param requestId
*/
@Override
public void setRequestId(String requestId) {
this.requestId = requestId;
}
/**
* requestId
*/
@Override
public void updateRequestId() {
ScriptExecutor scriptExecutor = SpringUtils.getBean(ScriptResolutionService.class).getScriptExecutor(sessionId);
if (scriptExecutor != null) {
scriptExecutor.setRequestId(this.requestId);
scriptExecutor.updateRequestId();
}
}
@Override
public void processRequest(DebuggerRequest request) {
log.debug("processRequest的projectId,{}",request.getProjectId());
@ -219,6 +274,16 @@ public class DefaultDebugSession implements DebugSession {
this.future = future;
}
private void startReplay() {
log.info("sessionId[{}]-requestId[{}]开放开始", sessionId, requestId);
this.replaying = true;
}
private void endReplay() {
log.info("sessionId[{}]-requestId[{}]开放结束", sessionId, requestId);
this.replaying = false;
}
/**
*
*
@ -275,7 +340,13 @@ public class DefaultDebugSession implements DebugSession {
} else if (DebugerConst.CommandConst.CMD_DEVICE_INIT.equalsIgnoreCase(cmd)) {//应用初始化处理
handleDeviceInit(request);
} else if (DebugerConst.CommandConst.CMD_REPLAY_START.equalsIgnoreCase(cmd)) {//回放指令处理
handleReplayStart(request);
try {
handleReplayStart(request);
} catch (Exception e) {
throw e;
} finally {
endReplay();
}
} else if (DebugerConst.CommandConst.CMD_SCREEN_SHOT.equalsIgnoreCase(cmd)) { //截图
handleScreenShot(request);
} else if (DebugerConst.CommandConst.CMD_DETECT_EXECUTE.equalsIgnoreCase(cmd)) { //隐式回放
@ -486,8 +557,9 @@ public class DefaultDebugSession implements DebugSession {
*/
private void handleReplayStart(DebuggerRequest request) {
log.debug("Begin to handle replay start");
startReplay();
String sessionId = request.getSessionId();
String requestId = request.getRequestId();
requestId = request.getRequestId();
String type = (String) request.getDataValue(DebugerConst.ReqConst.KEY_REPLAY_TYPE);
Object scriptData = request.getDataValue(DebugerConst.ReqConst.KEY_REPLAY_SCRIPT_DATA);
Script script = null;

View File

@ -168,6 +168,21 @@ public class DebugServiceImpl implements DebugService {
debugSession.stop(request);
return;
}
// 如果正在回放中遇到新的回放指令那么需要替换requestId因为前端将新的requestId替换成新的后台如果返回旧的requestId那么当前步骤的标识就会丢失
if (DebugerConst.CommandConst.CMD_REPLAY_START.equalsIgnoreCase(request.getCmd())) {
if (debugSession.isReplay()) { // 处于回放中
log.info("sessionId[{}]-requestId[{}]正在回放中接受到新的回放更新requestId[{}]",
debugSession.getSessionId(), debugSession.getRequestId(), request.getRequestId());
try {
Thread.sleep(500L); // 用于等待上一个回放指令的预处理
} catch (InterruptedException e) {
log.error("等待过程被打断");
}
debugSession.setRequestId(request.getRequestId());
debugSession.updateRequestId();
return; // 已经在回放,不接受新的回放指令信息
}
}
debugSession.processRequest(request);
}

View File

@ -98,4 +98,9 @@ public interface ScriptExecutor extends IScriptRuntimeContext{
*
*/
void empty();
/**
* requestId
*/
void updateRequestId();
}

View File

@ -2090,4 +2090,17 @@ public class ScriptRuntimeExecutor implements ScriptExecutor {
}
this.finishedTime = new Date();
}
/**
* requestId
*/
@Override
public void updateRequestId() {
if (!sonExecutorMap.isEmpty()) {
for (ScriptRuntimeExecutor son : sonExecutorMap.values()) {
son.setRequestId(this.requestId);
son.updateRequestId();
}
}
}
}