]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/thrift/test/hs/ThriftTestUtils.hs
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / jaegertracing / thrift / test / hs / ThriftTestUtils.hs
CommitLineData
f67539c2
TL
1--
2-- Licensed to the Apache Software Foundation (ASF) under one
3-- or more contributor license agreements. See the NOTICE file
4-- distributed with this work for additional information
5-- regarding copyright ownership. The ASF licenses this file
6-- to you under the Apache License, Version 2.0 (the
7-- "License"); you may not use this file except in compliance
8-- with the License. You may obtain a copy of the License at
9--
10-- http://www.apache.org/licenses/LICENSE-2.0
11--
12-- Unless required by applicable law or agreed to in writing,
13-- software distributed under the License is distributed on an
14-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15-- KIND, either express or implied. See the License for the
16-- specific language governing permissions and limitations
17-- under the License.
18--
19
20module ThriftTestUtils (ClientFunc, ServerFunc, clientLog, serverLog, testLog, runTest) where
21
22
23import qualified Control.Concurrent
24import qualified Network
25import qualified System.IO
26
27
28serverPort :: Network.PortNumber
29serverPort = 9090
30
31serverAddress :: (String, Network.PortID)
32serverAddress = ("localhost", Network.PortNumber serverPort)
33
34
35testLog :: String -> IO ()
36testLog str = do
37 System.IO.hPutStr System.IO.stdout $ str ++ "\n"
38 System.IO.hFlush System.IO.stdout
39
40
41clientLog :: String -> IO ()
42clientLog str = testLog $ "CLIENT: " ++ str
43
44serverLog :: String -> IO ()
45serverLog str = testLog $ "SERVER: " ++ str
46
47
48type ServerFunc = Network.PortNumber -> IO ()
49type ClientFunc = (String, Network.PortID) -> IO ()
50
51runTest :: ServerFunc -> ClientFunc -> IO ()
52runTest server client = do
53 _ <- Control.Concurrent.forkIO (server serverPort)
54
55 -- Fairly horrible; this does not 100% guarantees that the other thread
56 -- has actually opened the socket we need... but not much else we can do
57 -- without this, the client races the server to the socket, and wins every
58 -- time
59 Control.Concurrent.yield
60 Control.Concurrent.threadDelay $ 500 * 1000 -- unit is in _micro_seconds
61 Control.Concurrent.yield
62
63 client serverAddress
64
65 testLog "SUCCESS"