Repository navigation
Conversation
GeminiVisualTestHelper now throws GeminiUnavailableException (an IllegalStateException) when the last attempt still times out or gets a 429 or 5xx. BaseVisualTest gains an opt-in skipWhenGeminiUnavailable flag that reports the test as skipped instead of failed in that case. VisualMapSampleTest opts in, so a Gemini outage no longer fails CI.
Coverage (unit tests)No unit baseline recorded in
Line and branch coverage from unit test reports. History is recorded in |
| assertThat(error).hasMessageThat().contains("Gemini visual verification failed") | ||
| } | ||
|
|
||
| private fun unavailableGeminiHarness(skip: Boolean) = object : BaseVisualTest() { |
There was a problem hiding this comment.
if BaseVisualTest.skipWhenGeminiUnavailable's default value were accidentally flipped to true, this test would still pass. is it ok ??
There was a problem hiding this comment.
if BaseVisualTest.skipWhenGeminiUnavailable's default value were accidentally flipped to true, this test would still pass. is it ok ??
Good point, the test was setting explicitly the flag to false, so it never covered the default. Now unavailableGeminiHarness() leaves skipWhenGeminiUnavailable untouched, and I checked that flipping the default to true makes this test fail. Done in 52e04ae.
The fails-by-default test set the flag to false explicitly, so it would still pass if the default flipped to true. Its harness now leaves the flag at its default.
| if (isLastAttempt) { | ||
| Log.e(TAG, "Gemini API request failed after $attempt attempts", e) | ||
| throw e | ||
| throw GeminiUnavailableException("Gemini API request failed after $attempt attempts: $e", e) |
There was a problem hiding this comment.
All four public entry points calling executeWithRetry—analyzeImage, analyzeImageBlocking, performActionFromPrompt, and performActionFromPromptBlocking—now throw GeminiUnavailableException and should document it in KDoc.
Summary
Since #40,
GeminiVisualTestHelperretries timeouts,429and5xxthree times with backoff. That fixed the timeouts, but on Dec 2 Gemini answered503 UNAVAILABLE("This model is currently experiencing high demand") on all three attempts, twice in a row, so the emulator job on #39 still failed for a reason that has nothing to do with the code under test.This PR lets a visual test be reported as skipped instead of failed when Gemini is still unavailable after the last retry. It is opt-in, and the sample test opts in.
Changes
GeminiUnavailableException, thrown when the last attempt still times out or fails with a network error,429or5xx. It extendsIllegalStateException, so callers catching that keep working.BaseVisualTest.skipWhenGeminiUnavailable(defaultfalse): whentrue,verifyScreenshotWithGoldenFallbackturnsGeminiUnavailableExceptioninto anAssumptionViolatedException, the same mechanism already used whenGEMINI_API_KEYis missing. Gemini rejecting the screenshot,400, an invalid key and every other error still fail the test.VisualMapSampleTestsets it totrue, so a Gemini outage no longer breaks CI.Behaviour change
When every attempt times out, the helper now throws
GeminiUnavailableExceptionwith theHttpRequestTimeoutExceptionas its cause, instead of rethrowing theIOExceptionitself. Code catchingIOExceptionaroundanalyzeImagewould need to catchGeminiUnavailableExceptioninstead. Worth to mention in the next rc release notes.Verification
./gradlew :visual-testing:testDebugUnitTest --rerun-taskspasses (39 tests, 3 new: skip when opted in, fail by default, still fail on a rejected screenshot with skipping enabled;GeminiRetryTestupdated for the new exception type).apiCheck(api dump updated),spotlessCheck,:visual-testing:lintDebug,:app:lintDebugand:app:compileDebugAndroidTestKotlinpass.