Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 75c6ed7

Browse files
committed
Avoid timing sensitivity in test
1 parent 1608fdc commit 75c6ed7

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/Haskell/Ide/Engine/Transport/JsonStdio.hs

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ jsonStdioTransport cin = do
3737
P.runEffect (parseFrames PB.stdin P.>-> parseToJsonPipe cin cout 1 P.>-> jsonConsumer)
3838

3939
parseToJsonPipe
40-
:: Chan ChannelRequest
41-
-> Chan ChannelResponse
40+
:: TChan ChannelRequest
41+
-> TChan ChannelResponse
4242
-> Int
4343
-> P.Pipe (Either PAe.DecodingError WireRequest) A.Value IO ()
4444
parseToJsonPipe cin cout cid =
@@ -53,8 +53,8 @@ parseToJsonPipe cin cout cid =
5353
T.pack $ "jsonStdioTransport:parse error:" ++ show decodeErr
5454
P.yield $ A.toJSON $ channelToWire rsp
5555
Right req ->
56-
do liftIO $ writeChan cin (wireToChannel cout cid req)
57-
rsp <- liftIO $ readChan cout
56+
do liftIO $ atomically $ writeTChan cin (wireToChannel cout cid req)
57+
rsp <- liftIO $ atomically $ readTChan cout
5858
P.yield $ A.toJSON $ channelToWire rsp
5959
parseToJsonPipe cin
6060
cout

test/DispatcherSpec.hs

+8-10
Original file line numberDiff line numberDiff line change
@@ -232,16 +232,14 @@ dispatcherSpec = do
232232
r2 <- withStdoutLogging $ runIdeM (IdeState Map.empty) (doDispatch (testPlugins chSync) cr2)
233233
r1 `shouldBe` Nothing
234234
r2 `shouldBe` Nothing
235-
yield
236-
rc1 <- atomically $ tryReadTChan chan
237-
yield
238-
rc2 <- atomically $ tryReadTChan chan
239-
rc1 `shouldBe` Just (CResp { couPlugin = "test"
240-
, coutReqId = 2
241-
, coutResp = IdeResponseOk (HM.fromList [("response",String "asyncCmd2 sent strobe")])})
242-
rc2 `shouldBe` Just (CResp { couPlugin = "test"
243-
, coutReqId = 1
244-
, coutResp = IdeResponseOk (HM.fromList [("response",String "asyncCmd1 got strobe")])})
235+
rc1 <- atomically $ readTChan chan
236+
rc2 <- atomically $ readTChan chan
237+
rc1 `shouldBe` (CResp { couPlugin = "test"
238+
, coutReqId = 2
239+
, coutResp = IdeResponseOk (HM.fromList [("response",String "asyncCmd2 sent strobe")])})
240+
rc2 `shouldBe` (CResp { couPlugin = "test"
241+
, coutReqId = 1
242+
, coutResp = IdeResponseOk (HM.fromList [("response",String "asyncCmd1 got strobe")])})
245243

246244
-- ---------------------------------------------------------------------
247245

0 commit comments

Comments
 (0)