Skip to content

Commit d959d33

Browse files
committed
Handle 503 errors in integration test using withKnownIssue
1 parent ec5df60 commit d959d33

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

FirebaseVertexAI/Tests/TestApp/Tests/Integration/GenerateContentIntegrationTests.swift

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import VertexAITestApp
2323
import UIKit
2424
#endif // canImport(UIKit)
2525

26+
@testable import struct FirebaseVertexAI.BackendError
27+
2628
@Suite(.serialized)
2729
struct GenerateContentIntegrationTests {
2830
// Set temperature, topP and topK to lowest allowed values to make responses more deterministic.
@@ -140,18 +142,30 @@ struct GenerateContentIntegrationTests {
140142
)
141143
let prompt = "Generate an image of a cute cartoon kitten playing with a ball of yarn."
142144

143-
let response = try await model.generateContent(prompt)
145+
var response: GenerateContentResponse?
146+
try await withKnownIssue(
147+
"Backend may fail with a 503 - Service Unavailable error when overloaded",
148+
isIntermittent: true
149+
) {
150+
response = try await model.generateContent(prompt)
151+
} matching: { issue in
152+
(issue.error as? BackendError).map { $0.httpResponseCode == 503 } ?? false
153+
}
144154

155+
guard let response else { return }
145156
let candidate = try #require(response.candidates.first)
146157
let inlineDataPart = try #require(candidate.content.parts
147158
.first { $0 is InlineDataPart } as? InlineDataPart)
148159
#expect(inlineDataPart.mimeType == "image/png")
149160
#expect(inlineDataPart.data.count > 0)
150161
#if canImport(UIKit)
151162
let uiImage = try #require(UIImage(data: inlineDataPart.data))
152-
// Gemini 2.0 Flash Experimental returns 1024x1024 sized images.
153-
#expect(uiImage.size.width == 1024.0)
154-
#expect(uiImage.size.height == 1024.0)
163+
// Gemini 2.0 Flash Experimental returns images sized to fit within a 1024x1024 pixel box but
164+
// dimensions may vary depending on the aspect ratio.
165+
#expect(uiImage.size.width <= 1024)
166+
#expect(uiImage.size.width >= 500)
167+
#expect(uiImage.size.height <= 1024)
168+
#expect(uiImage.size.height >= 500)
155169
#endif // canImport(UIKit)
156170
}
157171

0 commit comments

Comments
 (0)