Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
fix: 🐛 enforce lower and upper file size limit when triggering analys…
Browse files Browse the repository at this point in the history
…is [ROAD-799][ROAD-814] (#37)

* feat: check for min and max file size when triggering analysis [ROAD-799]

also bump upload tries to 10
  • Loading branch information
bastiandoetsch authored Apr 7, 2022
1 parent cc044e1 commit 4d21c1f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [2.3.1] - 2022-04
- fix: adjust max file size to the correct size of 1MB (previously: 4000 bytes)
- chore: update upload attemps to 10

## [2.3.0] - 2022-03
- fix: make 5 consequent attempts to getAnalysis during polling if operation does not succeed with 404
- fix: make 5 attempts to re-upload files if operation does not succeed
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {

group = "io.snyk.code.sdk"
archivesBaseName = "snyk-code-client"
version = "2.3.0"
version = "2.3.1"

repositories {
mavenLocal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
public abstract class AnalysisDataBase {

public static final String COMPLETE = "COMPLETE";
public static final int MAX_FILE_SIZE = 1024 * 1024;
private final PlatformDependentUtilsBase pdUtils;
private final HashContentUtilsBase hashContentUtils;
private final DeepCodeParamsBase deepCodeParams;
Expand Down Expand Up @@ -411,7 +412,7 @@ private boolean uploadFilesStep(
} else if (missingFiles.isEmpty()) {
dcLogger.logInfo("No missingFiles to Upload");
} else {
final int attempts = 5;
final int attempts = 10;
int counter = 0;
while (!missingFiles.isEmpty() && counter < attempts) {
if (counter > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public List<Object> getAllSupportedFilesInProject(

protected abstract Collection<Object> allProjectFiles(@NotNull Object project);

private static final long MAX_FILE_SIZE = 4000000; // ~ 4MB in bytes
private static final long MAX_FILE_SIZE = 1024*1024; // 1MB in bytes

public boolean isSupportedFileFormat(@NotNull Object file) {
// DCLogger.getInstance().info("isSupportedFileFormat started for " + psiFile.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class GetAnalysisRequest {
* @param severity
* @param shard uniq String (hash) per Project to optimize jobs on backend (run on the same worker to reuse caches)
* @param ideProductName specific IDE
* @param orgDisplayName client’s snyk organization name
* @param orgDisplayName clients snyk organization name
* @param prioritized
* @param legacy
*/
Expand Down
23 changes: 20 additions & 3 deletions src/test/java/ai/deepcode/javaclient/core/AnalysisDataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import org.jetbrains.annotations.NotNull;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
Expand All @@ -38,6 +41,16 @@ public class AnalysisDataTest {
public @NotNull String getProjectName(@NotNull Object project) {
return project.toString();
}

@Override
public @NotNull String getFileName(@NotNull Object file) {
return "testFileName";
}

@Override
public long getFileSize(@NotNull Object file) {
return getFileName(file).length();
}
};

final DCLoggerBase dcLogger = new LoggerMock();
Expand Down Expand Up @@ -77,7 +90,7 @@ private static class RestApiMockWithBrokenFileUpload extends DeepCodeRestApiMock

// make 5 attempts to re-upload files if operation does not succeed
@Test
public void reupload_files_if_initial_upload_does_not_succeed() {
public void reupload_files_if_initial_upload_does_not_succeed() throws IOException {
final int[] reUploadCounter = {0};
restApi = new RestApiMockWithBrokenFileUpload() {
@Override
Expand All @@ -94,9 +107,13 @@ public void reupload_files_if_initial_upload_does_not_succeed() {
final String project = "Project1";
final String progress = "Progress Indicator";

analysisData.updateCachedResultsForFiles(project, Collections.singleton("File"), progress);
File file = File.createTempFile("analysisDataTest","tmp");
file.deleteOnExit();
Files.writeString(file.toPath(), "testtestest");

analysisData.updateCachedResultsForFiles(project, Collections.singleton(file), progress);

assertEquals("Should be made 5 attempts to re-upload files if operation does not succeed", 5, reUploadCounter[0]);
assertEquals("Should have made 10 attempts to re-upload files if operation does not succeed", 10, reUploadCounter[0]);
}

// do not try to getAnalysis if `upload files` is not succeed (i.e. `missingFiles` is not empty after uploads)
Expand Down

0 comments on commit 4d21c1f

Please sign in to comment.