Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for server request to complete so UI test breakpoints work as expected #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion Sources/Mussel/MusselTester.swift
Expand Up @@ -28,7 +28,23 @@ extension MusselTester {
request.httpBody = data
request.setValue("application/json", forHTTPHeaderField: "Content-Type")

let task = URLSession.shared.dataTask(with: request)
let dispatchGroup = DispatchGroup()

let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let error = error {
debugPrint("Mussel received error: \(error.localizedDescription)")
} else if let response = response as? HTTPURLResponse {
debugPrint("Mussel received response status code \(response.statusCode)")
} else {
debugPrint("Mussel request finished, but with an unexpected result. Maybe MusselServer isn't running?")
}
dispatchGroup.leave()
}

dispatchGroup.enter()
task.resume()

// Wait until the task completes
dispatchGroup.wait()
}
}