Skip to content

Commit

Permalink
Bugfix: count the task state in back-end (#650)
Browse files Browse the repository at this point in the history
<!-- 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)
  • Loading branch information
zhou9584 committed Jan 25, 2024
1 parent 6bf477e commit 3960c5a
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,26 @@ public void execute(AnalysisTask analysisTask, TestRun testRun) throws Exception
T report = initReport(analysisTask);
report.setTaskId(analysisTask.getId());
report.setTaskRunId(testRun.getId());

testRun.setTotalCount(analysisTask.getAnalysisConfigs().size());
for (AnalysisTask.AnalysisConfig config : analysisTask.getAnalysisConfigs()) {
String analysisType = config.getAnalysisType();
if (AnalysisTask.AnalysisType.LEAK_INFO.name().equals(analysisType)) {
report = scanSensitiveWords(report, analysisTask.getAppFile(), testRun.getResultFolder(), config, testRun.getLogger());
} else if (AnalysisTask.AnalysisType.FILE_SIZE.name().equals(analysisType)) {
report = analysisPackage(report, analysisTask.getAppFile(), testRun.getResultFolder(), config, testRun.getLogger());
try {
if (AnalysisTask.AnalysisType.LEAK_INFO.name().equals(analysisType)) {
report = scanSensitiveWords(report, analysisTask.getAppFile(), testRun.getResultFolder(), config, testRun.getLogger());
} else if (AnalysisTask.AnalysisType.FILE_SIZE.name().equals(analysisType)) {
report = analysisPackage(report, analysisTask.getAppFile(), testRun.getResultFolder(), config, testRun.getLogger());
} else {
testRun.oneMoreFailure();
testRun.getLogger().error("Unsupported analysis type: " + analysisType);
}
} catch (Exception e) {
testRun.oneMoreFailure();
testRun.getLogger().error("Failed to execute analysis task: " + analysisTask.getId() + " with analysis type: " + analysisType, e);
}
}
testRun.setTaskResult(report);
testRun.setSuccess(testRun.getFailCount() == 0);
}

abstract T initReport(AnalysisTask task);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,20 @@ public ApkReport analyzeApk(ApkReport report, String apkPath, Logger logger) {

sizeInMB = (float) Math.round(sizeInMB * 100) / 100;
report.getApkSizeReport().setDownloadSizeInMB(sizeInMB);
return report;
} catch (Exception e) {
logger.info("failed to get download size");
throw new RuntimeException(e);
}
}
logger.error("error in apk analyzer: {}", error);

logger.error("failed to get download size, code: {}, error: {}", code, error);
throw new RuntimeException(error);
} catch (InterruptedException e) {
logger.error("Interrupted in APK analyser", e);
throw new RuntimeException(e);
} catch (IOException e) {
logger.error("error in APK analyser", e);
throw new RuntimeException(e);
}
return report;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,14 @@ public ApkReport analyzeApk(ApkReport report, String apkPath, Logger logger) {
return getApkReportFromJsonReport(report, reportFile);
}
logger.info(error);
throw new RuntimeException(error);
} catch (InterruptedException e) {
logger.error("Interrupted in analyzeApk", e);
throw new RuntimeException(e);
} catch (IOException e) {
logger.error("error in analyzeApk", e);
throw new RuntimeException(e);
}
return report;
}

public static ApkReport getApkReportFromJsonReport(ApkReport apkReport, File file) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,14 @@ public ApkReport analyzeLeaks(ApkReport report, String apkPath, Map<String, Stri
return getLeaksFromJsonReport(report, reportFile);
}
logger.error("error in apk leaks: {}", error);
throw new RuntimeException(error);
} catch (InterruptedException e) {
logger.error("Interrupted in APK leaks scan", e);
throw new RuntimeException(e);
} catch (IOException e) {
logger.error("error in APK leaks scan", e);
throw new RuntimeException(e);
}
return report;
}

private ApkReport getLeaksFromJsonReport(ApkReport report, File file) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public Result<Object> getTaskStatus(@CurrentSecurityContext SysUser requestor,
// if (!sysUserService.checkUserAdmin(requestor) && !userTeamManagementService.checkRequestorTeamRelation(requestor, testTask.getTeamId())) {
// return Result.error(HttpStatus.UNAUTHORIZED.value(), "Unauthorized, the TestTask doesn't belong to user's Teams");
// }
task.setDeviceTestResults(task.getTaskRunList());
return Result.ok(task);
}
TestTaskQueuedInfo queuedInfo = testTaskService.getTestQueuedInfo(testId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,21 @@ public void saveTaskDataFromAgent(Task task, boolean persistence, String agentId

@CachePut(key = "#task.id")
public Task saveTaskData(Task task) {
taskRepository.save(task);
List<TestRun> deviceTestResults = task.getTaskRunList();
if (deviceTestResults.isEmpty()) {
task.setSucceed(false);
taskRepository.save(task);
return task;
}
boolean isSuccess = true;
for (TestRun deviceTestResult : deviceTestResults) {
if (!deviceTestResult.isSuccess()) {
isSuccess = false;
break;
}
}
task.setSucceed(isSuccess);
taskRepository.save(task);

testRunRepository.saveAll(deviceTestResults);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ public class Task implements Serializable {
private String notifyUrl;
@Transient
private boolean disableRecording = false;
@Column(columnDefinition = "boolean default false")
private boolean isSucceed = false;

@Transient
@Deprecated
private List<TestRun> deviceTestResults = taskRunList;
private List<TestRun> deviceTestResults;

public synchronized void addTestedDeviceResult(TestRun deviceTestResult) {
taskRunList.add(deviceTestResult);
Expand Down
8 changes: 4 additions & 4 deletions react/src/component/TasksView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -702,15 +702,15 @@ class TasksView extends BaseView {
if (this.state.selectedParams.Result.length < 2) {
if (this.state.selectedParams.Result.includes('Passed')) {
queryParams.push({
"key": "totalFailCount",
"key": "isSucceed",
"op": "equal",
"value": 0
"value": 1
})
}
if (this.state.selectedParams.Result.includes('Failed')) {
queryParams.push({
"key": "totalFailCount",
"op": "gt",
"key": "isSucceed",
"op": "equal",
"value": 0
})
}
Expand Down

0 comments on commit 3960c5a

Please sign in to comment.