Skip to content

Commit 0f87405

Browse files
author
Di Wu
authored
test(api): fix flaky integration test cases (#2787)
1 parent 1cbb1f4 commit 0f87405

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

AmplifyPlugins/API/Tests/APIHostApp/APIHostApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginFunctionalTests/GraphQLConnectionScenario2Tests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class GraphQLConnectionScenario2Tests: XCTestCase {
4949

5050
override func tearDown() async throws {
5151
await Amplify.reset()
52+
try await Task.sleep(seconds: 1)
5253
}
5354

5455
// Create Project2 in different ways, then retrieve it

AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginFunctionalTests/GraphQLConnectionScenario3Tests+List.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,18 @@ extension GraphQLConnectionScenario3Tests {
159159
XCTFail("Could not create comment")
160160
return
161161
}
162+
162163
let predicate = Comment3.keys.postID.eq(post.id)
163-
let result = try await Amplify.API.query(request: .list(Comment3.self, where: predicate))
164-
switch result {
165-
case .success(let comments):
166-
XCTAssertEqual(comments.count, 1)
167-
case .failure(let response):
168-
XCTFail("Failed with: \(response)")
164+
guard case .success(var comments) = try await Amplify.API.query(request: .list(Comment3.self, where: predicate))
165+
else {
166+
XCTFail("Failed to retrieve comments")
167+
return
168+
}
169+
170+
while comments.count == 0 && comments.hasNextPage() {
171+
comments = try await comments.getNextPage()
169172
}
173+
XCTAssertEqual(comments.count, 1)
170174
}
171175

172176
/// Test paginated list query returns a List containing pagination functionality. This test also aggregates page

AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginFunctionalTests/GraphQLConnectionScenario3Tests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class GraphQLConnectionScenario3Tests: XCTestCase {
4949

5050
override func tearDown() async throws {
5151
await Amplify.reset()
52+
try await Task.sleep(seconds: 1)
5253
}
5354

5455
func testQuerySinglePost() async throws {

AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginLazyLoadTests/GraphQLLazyLoadBaseTest.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class GraphQLLazyLoadBaseTest: XCTestCase {
2121

2222
override func tearDown() async throws {
2323
await Amplify.reset()
24+
try await Task.sleep(seconds: 1)
2425
}
2526

2627
func setupConfig() {

0 commit comments

Comments
 (0)