Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry dsci modification #83

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/main/java/io/odh/test/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -213,4 +214,28 @@ public static Path getLogPath(String folderName, String testClassName, String te
}
return path;
}

/**
* Repeat command n-times
*
* @param retry count of remaining retries
* @param fn request function
* @return The value from the first successful call to the callable
*/
public static <T> T runUntilPass(int retry, Callable<T> fn) {
for (int i = 0; i < retry; i++) {
try {
LOGGER.debug("Running command, attempt: {}", i);
return fn.call();
} catch (Exception | AssertionError ex) {
LOGGER.warn("Command failed", ex);
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
throw new IllegalStateException(String.format("Command wasn't pass in %s attempts", retry));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public DSCInitialization get(String namespace, String name) {
@Override
public void create(DSCInitialization resource) {
if (get("", resource.getMetadata().getName()) == null) {
dsciClient().resource(resource).create();
TestUtils.runUntilPass(5, () -> dsciClient().resource(resource).create());
} else {
dsciClient().resource(resource).update();
TestUtils.runUntilPass(5, () -> dsciClient().resource(resource).update());
}
}

Expand All @@ -41,7 +41,7 @@ public void delete(DSCInitialization resource) {

@Override
public void update(DSCInitialization resource) {
dsciClient().resource(resource).update();
TestUtils.runUntilPass(5, () -> dsciClient().resource(resource).update());
}

@Override
Expand Down
Loading