/* * Copyright 2017, gRPC Authors All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import XCTest import Foundation import Dispatch @testable import gRPC func Log(_ message : String) { FileHandle.standardError.write((message + "\n").data(using:.utf8)!) } class gRPCTests: XCTestCase { func testBasicSanity() { gRPC.initialize() let sem = DispatchSemaphore(value: 0) // start the server DispatchQueue.global().async() { do { try runServer() } catch (let error) { XCTFail("server error \(error)") } sem.signal() // when the server exits, the test is finished } // run the client do { try runClient() } catch (let error) { XCTFail("client error \(error)") } // stop the server server.stop() // wait until the server has shut down _ = sem.wait(timeout: DispatchTime.distantFuture) } } extension gRPCTests { static var allTests : [(String, (gRPCTests) -> () throws -> Void)] { return [ ("testBasicSanity", testBasicSanity), ] } } let address = "localhost:8998" let host = "foo.test.google.fr" let clientText = "hello, server!" let serverText = "hello, client!" let initialClientMetadata = ["x": "xylophone", "y": "yu", "z": "zither"] let initialServerMetadata = ["a": "Apple", "b": "Banana", "c": "Cherry"] let trailingServerMetadata = ["0": "zero", "1": "one", "2": "two"] let steps = 1 let hello = "/hello" let statusCode = 0 let statusMessage = "OK" let server = gRPC.Server(address:address) func verify_metadata(_ metadata: Metadata, expected: [String:String]) { XCTAssertGreaterThanOrEqual(metadata.count(), expected.count) for i in 0..