Repository: Moya/Moya
File: Tests/MoyaTests/MoyaProviderIntegrationTests.swift (Swift)

Code before:
                        }

                        expect(response).toNot(beNil())
                        expect(response?.statusCode).to(equal(400))
                    }

                    it("uses a custom Alamofire.Manager request generation") {
                        let session = StubSession()
                        let provider = MoyaProvider<GitHub>(session: session)

                        waitUntil { done in
                            provider.request(.zen) { _ in done() }
                        }

                        expect(session.called) == true
                    }

                    it("uses a background queue") {

                        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.wrappedValue = Thread.isMainThread
                                done()
                            }
                        }

                        expect(isMainThread.wrappedValue) == false
                    }

                    it("uses the main queue") {
                        var isMainThread: Bool?
                        let target: GitHub = .zen
                        waitUntil { done in
                            provider.request(target) { _ in
                                isMainThread = Thread.isMainThread
                                done()
                            }
                        }

                        expect(isMainThread) == true
                    }
                }

                describe("a provider with credential plugin") {
                    it("credential closure returns nil") {
                        var called = false
                        let plugin = CredentialsPlugin { _ in

Review comment (suggestion):
I know that this was there before, but this is probably a bad check - main thread can be reused in a background queue, so we probably should check for a specific queue instead (similar to the labels we used before)

Code after:
                        }

                        expect(response).toNot(beNil())
                        expect(response?.statusCode).to(equal(400))
                    }

                    it("uses a custom Alamofire.Manager request generation") {
                        let session = StubSession()
                        let provider = MoyaProvider<GitHub>(session: session)

                        waitUntil { done in
                            provider.request(.zen) { _ in done() }
                        }

                        expect(session.called) == true
                    }

                    it("uses a background queue") {

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

                        waitUntil { done in
                            provider.request(target, callbackQueue: callbackQueue) { _ in
                                callbackQueueLabel.wrappedValue = DispatchQueue.currentLabel
                                done()
                            }
                        }

                        expect(callbackQueueLabel.wrappedValue) == "background_queue"
                    }

                    it("uses the main queue") {
                        var isMainThread: Bool?
                        let target: GitHub = .zen
                        waitUntil { done in
                            provider.request(target) { _ in
                                isMainThread = Thread.isMainThread
                                done()
                            }
                        }

                        expect(isMainThread) == true
                    }
                }

                describe("a provider with credential plugin") {
                    it("credential closure returns nil") {
                        var called = false
                        let plugin = CredentialsPlugin { _ in