Skip to content

Commit b3d3997

Browse files
authored
chore: fix stress tests (#4108)
1 parent ee6b2fa commit b3d3997

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

.github/workflows/stress_test.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ jobs:
6868
scheme: AuthStressTests
6969
destination: ${{ env.DESTINATION }}
7070
xcode_path: '/Applications/Xcode_${{ env.XCODE_VERSION }}.app'
71+
other_flags: -parallel-testing-enabled NO
7172

7273
geo-stress-test:
7374
needs: prepare-for-test
@@ -99,6 +100,7 @@ jobs:
99100
scheme: GeoStressTests
100101
destination: ${{ env.DESTINATION }}
101102
xcode_path: '/Applications/Xcode_${{ env.XCODE_VERSION }}.app'
103+
other_flags: -parallel-testing-enabled NO
102104

103105
storage-stress-test:
104106
needs: prepare-for-test
@@ -130,6 +132,7 @@ jobs:
130132
scheme: StorageStressTests
131133
destination: ${{ env.DESTINATION }}
132134
xcode_path: '/Applications/Xcode_${{ env.XCODE_VERSION }}.app'
135+
other_flags: -parallel-testing-enabled NO
133136

134137
datastore-stress-test:
135138
needs: prepare-for-test
@@ -161,6 +164,7 @@ jobs:
161164
scheme: DatastoreStressTests
162165
destination: ${{ env.DESTINATION }}
163166
xcode_path: '/Applications/Xcode_${{ env.XCODE_VERSION }}.app'
167+
other_flags: -parallel-testing-enabled NO
164168

165169
graphql-api-stress-test:
166170
needs: prepare-for-test
@@ -191,4 +195,5 @@ jobs:
191195
project_path: ./AmplifyPlugins/API/Tests/APIHostApp
192196
scheme: GraphQLAPIStressTests
193197
destination: ${{ env.DESTINATION }}
194-
xcode_path: '/Applications/Xcode_${{ env.XCODE_VERSION }}.app'
198+
xcode_path: '/Applications/Xcode_${{ env.XCODE_VERSION }}.app'
199+
other_flags: -parallel-testing-enabled NO

AmplifyPlugins/API/Tests/APIHostApp/GraphQLAPIStressTests/GraphQLAPIStressTests.swift

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ final class APIStressTests: XCTestCase {
7575
let progressInvoked = expectation(description: "progress invoked")
7676
progressInvoked.expectedFulfillmentCount = concurrencyLimit
7777

78-
let uuid = UUID().uuidString
7978
let testMethodName = String("\(#function)".dropLast(2))
8079
let title = testMethodName + "Title"
8180

@@ -98,7 +97,7 @@ final class APIStressTests: XCTestCase {
9897
case .data(let result):
9998
switch result {
10099
case .success(let post):
101-
if post.id == uuid {
100+
if post.title == title {
102101
progressInvoked.fulfill()
103102
}
104103
case .failure(let error):
@@ -118,7 +117,7 @@ final class APIStressTests: XCTestCase {
118117
let sequenceCount = await sequenceActor.sequences.count
119118
XCTAssertEqual(sequenceCount, concurrencyLimit)
120119

121-
guard try await createPost(id: uuid, title: title) != nil else {
120+
guard try await Self.createPost(id: UUID().uuidString, title: title) != nil else {
122121
XCTFail("Failed to create post")
123122
return
124123
}
@@ -144,7 +143,7 @@ final class APIStressTests: XCTestCase {
144143
Task {
145144
let id = UUID().uuidString
146145
let title = "title" + String(index)
147-
let post = try await createPost(id: id, title: title)
146+
let post = try await APIStressTests.createPost(id: id, title: title)
148147
XCTAssertNotNil(post)
149148
XCTAssertEqual(id, post?.id)
150149
XCTAssertEqual(title, post?.title)
@@ -169,7 +168,7 @@ final class APIStressTests: XCTestCase {
169168
Task {
170169
let id = UUID().uuidString
171170
let title = "title" + String(index)
172-
let post = try await createPost(id: id, title: title)
171+
let post = try await APIStressTests.createPost(id: id, title: title)
173172
XCTAssertNotNil(post)
174173
XCTAssertEqual(id, post?.id)
175174
XCTAssertEqual(title, post?.title)
@@ -184,7 +183,7 @@ final class APIStressTests: XCTestCase {
184183
Task {
185184
var post = await postActor.posts[index]
186185
post.title = "newTitle" + String(index)
187-
let updatedPost = try await mutatePost(post)
186+
let updatedPost = try await APIStressTests.mutatePost(post)
188187
XCTAssertNotNil(updatedPost)
189188
XCTAssertEqual(post.id, updatedPost.id)
190189
XCTAssertEqual(post.title, updatedPost.title)
@@ -211,7 +210,7 @@ final class APIStressTests: XCTestCase {
211210
Task {
212211
let id = UUID().uuidString
213212
let title = "title" + String(index)
214-
let post = try await createPost(id: id, title: title)
213+
let post = try await APIStressTests.createPost(id: id, title: title)
215214
XCTAssertNotNil(post)
216215
XCTAssertEqual(id, post?.id)
217216
XCTAssertEqual(title, post?.title)
@@ -225,7 +224,7 @@ final class APIStressTests: XCTestCase {
225224
DispatchQueue.concurrentPerform(iterations: concurrencyLimit) { index in
226225
Task {
227226
let post = await postActor.posts[index]
228-
let deletedPost = try await deletePost(post: post)
227+
let deletedPost = try await APIStressTests.deletePost(post: post)
229228
XCTAssertNotNil(deletedPost)
230229
XCTAssertEqual(post.id, deletedPost.id)
231230
XCTAssertEqual(post.title, deletedPost.title)
@@ -252,7 +251,7 @@ final class APIStressTests: XCTestCase {
252251
Task {
253252
let id = UUID().uuidString
254253
let title = "title" + String(index)
255-
let post = try await createPost(id: id, title: title)
254+
let post = try await APIStressTests.createPost(id: id, title: title)
256255
XCTAssertNotNil(post)
257256
XCTAssertEqual(id, post?.id)
258257
XCTAssertEqual(title, post?.title)
@@ -301,12 +300,12 @@ final class APIStressTests: XCTestCase {
301300

302301
// MARK: - Helpers
303302

304-
func createPost(id: String, title: String) async throws -> Post? {
303+
static func createPost(id: String, title: String) async throws -> Post? {
305304
let post = Post(id: id, title: title, status: .active, content: "content")
306305
return try await createPost(post: post)
307306
}
308307

309-
func createPost(post: Post) async throws -> Post? {
308+
static func createPost(post: Post) async throws -> Post? {
310309
let data = try await Amplify.API.mutate(request: .create(post))
311310
switch data {
312311
case .success(let post):
@@ -316,7 +315,7 @@ final class APIStressTests: XCTestCase {
316315
}
317316
}
318317

319-
func mutatePost(_ post: Post) async throws -> Post {
318+
static func mutatePost(_ post: Post) async throws -> Post {
320319
let data = try await Amplify.API.mutate(request: .update(post))
321320
switch data {
322321
case .success(let post):
@@ -326,7 +325,7 @@ final class APIStressTests: XCTestCase {
326325
}
327326
}
328327

329-
func deletePost(post: Post) async throws -> Post {
328+
static func deletePost(post: Post) async throws -> Post {
330329
let data = try await Amplify.API.mutate(request: .delete(post))
331330
switch data {
332331
case .success(let post):

0 commit comments

Comments
 (0)