Skip to content

Commit 3960c5a

Browse files
authored
Bugfix: count the task state in back-end (#650)
<!-- Please provide brief information about the PR, what it contains & its purpose, new behaviors after the change. And let us know here if you need any help: https://github.com/microsoft/HydraLab/issues/new --> ## Description <!-- A few words to explain your changes --> ### Linked GitHub issue ID: # ## Pull Request Checklist <!-- Put an x in the boxes that apply. This is simply a reminder of what we are going to look for before merging your code. --> - [ ] Tests for the changes have been added (for bug fixes / features) - [x] Code compiles correctly with all tests are passed. - [x] I've read the [contributing guide](https://github.com/microsoft/HydraLab/blob/main/CONTRIBUTING.md#making-changes-to-the-code) and followed the recommended practices. - [ ] [Wikis](https://github.com/microsoft/HydraLab/wiki) or [README](https://github.com/microsoft/HydraLab/blob/main/README.md) have been reviewed and added / updated if needed (for bug fixes / features) ### Does this introduce a breaking change? *If this introduces a breaking change for Hydra Lab users, please describe the impact and migration path.* - [x] Yes - [ ] No ## How you tested it *Please make sure the change is tested, you can test it by adding UTs, do local test and share the screenshots, etc.* Please check the type of change your PR introduces: - [x] Bugfix - [ ] Feature - [ ] Technical design - [ ] Build related changes - [ ] Refactoring (no functional changes, no api changes) - [ ] Code style update (formatting, renaming) or Documentation content changes - [ ] Other (please describe): ### Feature UI screenshots or Technical design diagrams *If this is a relatively large or complex change, kick it off by drawing the tech design with PlantUML and explaining why you chose the solution you did and what alternatives you considered, etc...* ![image](https://github.com/microsoft/HydraLab/assets/26757995/11615f46-4120-480d-ab07-10fc45816530)
1 parent 6bf477e commit 3960c5a

File tree

8 files changed

+46
-17
lines changed

8 files changed

+46
-17
lines changed

agent/src/main/java/com/microsoft/hydralab/agent/runner/analysis/scanner/Scanner.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,26 @@ public void execute(AnalysisTask analysisTask, TestRun testRun) throws Exception
2929
T report = initReport(analysisTask);
3030
report.setTaskId(analysisTask.getId());
3131
report.setTaskRunId(testRun.getId());
32+
33+
testRun.setTotalCount(analysisTask.getAnalysisConfigs().size());
3234
for (AnalysisTask.AnalysisConfig config : analysisTask.getAnalysisConfigs()) {
3335
String analysisType = config.getAnalysisType();
34-
if (AnalysisTask.AnalysisType.LEAK_INFO.name().equals(analysisType)) {
35-
report = scanSensitiveWords(report, analysisTask.getAppFile(), testRun.getResultFolder(), config, testRun.getLogger());
36-
} else if (AnalysisTask.AnalysisType.FILE_SIZE.name().equals(analysisType)) {
37-
report = analysisPackage(report, analysisTask.getAppFile(), testRun.getResultFolder(), config, testRun.getLogger());
36+
try {
37+
if (AnalysisTask.AnalysisType.LEAK_INFO.name().equals(analysisType)) {
38+
report = scanSensitiveWords(report, analysisTask.getAppFile(), testRun.getResultFolder(), config, testRun.getLogger());
39+
} else if (AnalysisTask.AnalysisType.FILE_SIZE.name().equals(analysisType)) {
40+
report = analysisPackage(report, analysisTask.getAppFile(), testRun.getResultFolder(), config, testRun.getLogger());
41+
} else {
42+
testRun.oneMoreFailure();
43+
testRun.getLogger().error("Unsupported analysis type: " + analysisType);
44+
}
45+
} catch (Exception e) {
46+
testRun.oneMoreFailure();
47+
testRun.getLogger().error("Failed to execute analysis task: " + analysisTask.getId() + " with analysis type: " + analysisType, e);
3848
}
3949
}
4050
testRun.setTaskResult(report);
51+
testRun.setSuccess(testRun.getFailCount() == 0);
4152
}
4253

4354
abstract T initReport(AnalysisTask task);

agent/src/main/java/com/microsoft/hydralab/agent/runner/analysis/scanner/apk/ApkAnalyzeExecutor.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,20 @@ public ApkReport analyzeApk(ApkReport report, String apkPath, Logger logger) {
7676

7777
sizeInMB = (float) Math.round(sizeInMB * 100) / 100;
7878
report.getApkSizeReport().setDownloadSizeInMB(sizeInMB);
79+
return report;
7980
} catch (Exception e) {
8081
logger.info("failed to get download size");
82+
throw new RuntimeException(e);
8183
}
8284
}
83-
logger.error("error in apk analyzer: {}", error);
84-
85+
logger.error("failed to get download size, code: {}, error: {}", code, error);
86+
throw new RuntimeException(error);
8587
} catch (InterruptedException e) {
8688
logger.error("Interrupted in APK analyser", e);
89+
throw new RuntimeException(e);
8790
} catch (IOException e) {
8891
logger.error("error in APK analyser", e);
92+
throw new RuntimeException(e);
8993
}
90-
return report;
9194
}
92-
9395
}

agent/src/main/java/com/microsoft/hydralab/agent/runner/analysis/scanner/apk/ApkCanaryExecutor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,14 @@ public ApkReport analyzeApk(ApkReport report, String apkPath, Logger logger) {
160160
return getApkReportFromJsonReport(report, reportFile);
161161
}
162162
logger.info(error);
163+
throw new RuntimeException(error);
163164
} catch (InterruptedException e) {
164165
logger.error("Interrupted in analyzeApk", e);
166+
throw new RuntimeException(e);
165167
} catch (IOException e) {
166168
logger.error("error in analyzeApk", e);
169+
throw new RuntimeException(e);
167170
}
168-
return report;
169171
}
170172

171173
public static ApkReport getApkReportFromJsonReport(ApkReport apkReport, File file) {

agent/src/main/java/com/microsoft/hydralab/agent/runner/analysis/scanner/apk/ApkLeaksExecutor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,14 @@ public ApkReport analyzeLeaks(ApkReport report, String apkPath, Map<String, Stri
124124
return getLeaksFromJsonReport(report, reportFile);
125125
}
126126
logger.error("error in apk leaks: {}", error);
127+
throw new RuntimeException(error);
127128
} catch (InterruptedException e) {
128129
logger.error("Interrupted in APK leaks scan", e);
130+
throw new RuntimeException(e);
129131
} catch (IOException e) {
130132
logger.error("error in APK leaks scan", e);
133+
throw new RuntimeException(e);
131134
}
132-
return report;
133135
}
134136

135137
private ApkReport getLeaksFromJsonReport(ApkReport report, File file) {

center/src/main/java/com/microsoft/hydralab/center/controller/TestTaskController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ public Result<Object> getTaskStatus(@CurrentSecurityContext SysUser requestor,
135135
// if (!sysUserService.checkUserAdmin(requestor) && !userTeamManagementService.checkRequestorTeamRelation(requestor, testTask.getTeamId())) {
136136
// return Result.error(HttpStatus.UNAUTHORIZED.value(), "Unauthorized, the TestTask doesn't belong to user's Teams");
137137
// }
138+
task.setDeviceTestResults(task.getTaskRunList());
138139
return Result.ok(task);
139140
}
140141
TestTaskQueuedInfo queuedInfo = testTaskService.getTestQueuedInfo(testId);

center/src/main/java/com/microsoft/hydralab/center/service/TestDataService.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,21 @@ public void saveTaskDataFromAgent(Task task, boolean persistence, String agentId
196196

197197
@CachePut(key = "#task.id")
198198
public Task saveTaskData(Task task) {
199-
taskRepository.save(task);
200199
List<TestRun> deviceTestResults = task.getTaskRunList();
201200
if (deviceTestResults.isEmpty()) {
201+
task.setSucceed(false);
202+
taskRepository.save(task);
202203
return task;
203204
}
205+
boolean isSuccess = true;
206+
for (TestRun deviceTestResult : deviceTestResults) {
207+
if (!deviceTestResult.isSuccess()) {
208+
isSuccess = false;
209+
break;
210+
}
211+
}
212+
task.setSucceed(isSuccess);
213+
taskRepository.save(task);
204214

205215
testRunRepository.saveAll(deviceTestResults);
206216

common/src/main/java/com/microsoft/hydralab/common/entity/common/Task.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,11 @@ public class Task implements Serializable {
8484
private String notifyUrl;
8585
@Transient
8686
private boolean disableRecording = false;
87+
@Column(columnDefinition = "boolean default false")
88+
private boolean isSucceed = false;
8789

8890
@Transient
89-
@Deprecated
90-
private List<TestRun> deviceTestResults = taskRunList;
91+
private List<TestRun> deviceTestResults;
9192

9293
public synchronized void addTestedDeviceResult(TestRun deviceTestResult) {
9394
taskRunList.add(deviceTestResult);

react/src/component/TasksView.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -702,15 +702,15 @@ class TasksView extends BaseView {
702702
if (this.state.selectedParams.Result.length < 2) {
703703
if (this.state.selectedParams.Result.includes('Passed')) {
704704
queryParams.push({
705-
"key": "totalFailCount",
705+
"key": "isSucceed",
706706
"op": "equal",
707-
"value": 0
707+
"value": 1
708708
})
709709
}
710710
if (this.state.selectedParams.Result.includes('Failed')) {
711711
queryParams.push({
712-
"key": "totalFailCount",
713-
"op": "gt",
712+
"key": "isSucceed",
713+
"op": "equal",
714714
"value": 0
715715
})
716716
}

0 commit comments

Comments
 (0)