Skip to content

Commit

Permalink
TSAN: A couple of tests data races caught by TSAN fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
LucianoPAlmeida committed Feb 18, 2020
1 parent b3dd577 commit 2dc1da5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Tests/MoyaTests/MoyaProvider+RxSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,17 @@ final class MoyaProviderRxSpec: QuickSpec {
context("the callback queue is provided with the request") {
it("invokes the callback on the request queue") {
let requestQueue = DispatchQueue(label: UUID().uuidString)
var callbackQueueLabel: String?
let callbackQueueLabel = Atomic<String?>(wrappedValue: nil)

waitUntil(action: { completion in
provider.rx.request(.zen, callbackQueue: requestQueue)
.subscribe(onSuccess: { _ in
callbackQueueLabel = DispatchQueue.currentLabel
callbackQueueLabel.wrappedValue = DispatchQueue.currentLabel
completion()
}).disposed(by: disposeBag)
})

expect(callbackQueueLabel) == requestQueue.label
expect(callbackQueueLabel.wrappedValue) == requestQueue.label
}
}

Expand Down
7 changes: 4 additions & 3 deletions Tests/MoyaTests/MoyaProviderIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,19 @@ final class MoyaProviderIntegrationTests: QuickSpec {
}

it("uses a background queue") {
var isMainThread: Bool?

let isMainThread = Atomic<Bool?>(wrappedValue: nil)
let callbackQueue = DispatchQueue(label: "background_queue", attributes: .concurrent)
let target: GitHub = .zen

waitUntil { done in
provider.request(target, callbackQueue: callbackQueue) { _ in
isMainThread = Thread.isMainThread
isMainThread.wrappedValue = Thread.isMainThread
done()
}
}

expect(isMainThread) == false
expect(isMainThread.wrappedValue) == false
}

it("uses the main queue") {
Expand Down

0 comments on commit 2dc1da5

Please sign in to comment.