-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add build status badge to README and update OpenAiCompatibleV1ApiCont…
…rollerTest (#184) * Fail testFarmWithSunspotsSiloOpenAI * chore: Update OpenAiCompatibleV1ApiControllerTest with new models and tests * chore: Update OpenAiCompatibleV1ApiControllerTest with new models and tests * chore: Update README.md with build status badge * chore: Remove TODO comment * chore: Add RetryOnExceptionsExtension for test execution exception handling * chore: Add RetryOnExceptionsExtension for test execution exception handling * Revert back to "gpt-4o" (instead of "gpt-4o-mini") for OpenAiCompatibleV1ApiControllerTest due too many IOException --------- Co-authored-by: Arnaud Mengus <[email protected]>
- Loading branch information
1 parent
4f6d576
commit dfa4b07
Showing
5 changed files
with
258 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...est/java/ai/dragon/test/AbstractTest.java → ...st/java/ai/dragon/junit/AbstractTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
backend/src/test/java/ai/dragon/junit/extension/retry/RetryOnExceptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package ai.dragon.junit.extension.retry; | ||
|
||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@ExtendWith(RetryOnExceptionsExtension.class) | ||
public @interface RetryOnExceptions { | ||
int value() default 3; // Default retry count | ||
Class<? extends Throwable>[] onExceptions() default { Throwable.class }; // Exceptions to retry on | ||
} |
51 changes: 51 additions & 0 deletions
51
backend/src/test/java/ai/dragon/junit/extension/retry/RetryOnExceptionsExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package ai.dragon.junit.extension.retry; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import org.junit.jupiter.api.extension.BeforeEachCallback; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.junit.jupiter.api.extension.ExtensionContext.Store; | ||
import org.junit.jupiter.api.extension.TestExecutionExceptionHandler; | ||
|
||
public class RetryOnExceptionsExtension implements TestExecutionExceptionHandler, BeforeEachCallback { | ||
|
||
@Override | ||
public void handleTestExecutionException(ExtensionContext context, Throwable throwable) throws Throwable { | ||
Method testMethod = context.getRequiredTestMethod(); | ||
RetryOnExceptions retry = testMethod.getAnnotation(RetryOnExceptions.class); | ||
|
||
if (retry != null) { | ||
int maxRetries = retry.value(); | ||
Class<? extends Throwable>[] retryOnExceptions = retry.onExceptions(); | ||
Store store = context.getStore(ExtensionContext.Namespace.create(testMethod)); | ||
|
||
int currentRetries = store.getOrDefault("retries", Integer.class, 0); | ||
|
||
boolean shouldRetry = false; | ||
for (Class<? extends Throwable> retryOnException : retryOnExceptions) { | ||
if (retryOnException.isInstance(throwable)) { | ||
shouldRetry = true; | ||
break; | ||
} | ||
} | ||
|
||
if (shouldRetry && currentRetries < maxRetries) { | ||
store.put("retries", currentRetries + 1); | ||
context.getRequiredTestMethod().invoke(context.getRequiredTestInstance()); | ||
} else { | ||
throw throwable; | ||
} | ||
} else { | ||
throw throwable; | ||
} | ||
} | ||
|
||
@Override | ||
public void beforeEach(ExtensionContext context) throws Exception { | ||
Method testMethod = context.getRequiredTestMethod(); | ||
if (testMethod.isAnnotationPresent(RetryOnExceptions.class)) { | ||
Store store = context.getStore(ExtensionContext.Namespace.create(testMethod)); | ||
store.put("retries", 0); // Reset retry count before each test | ||
} | ||
} | ||
} |