mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-25 20:44:38 +00:00
core: fix flaky testAppSettings for virtual terminal getDiff race
Long command echo may be split by virtual terminal getDiff when readTerminalOutput observes intermediate window states between individual termCommand atomically blocks. Skip echo check for long commands and search for the expected response instead.
This commit is contained in:
@@ -16,7 +16,8 @@ import ChatTests.DBUtils
|
||||
import ChatTests.Utils
|
||||
import Control.Concurrent (threadDelay)
|
||||
import Control.Concurrent.Async (concurrently_)
|
||||
import Control.Monad (forM_, void)
|
||||
import Control.Monad (forM_, unless, void)
|
||||
import System.Timeout (timeout)
|
||||
import Data.Aeson (ToJSON)
|
||||
import qualified Data.Aeson as J
|
||||
import qualified Data.ByteString.Char8 as B
|
||||
@@ -2770,15 +2771,24 @@ testAppSettings ps =
|
||||
withNewTestChat ps "alice" aliceProfile $ \alice -> do
|
||||
let settings = T.unpack . safeDecodeUtf8 . LB.toStrict $ J.encode defaultAppSettings
|
||||
settingsApp = T.unpack . safeDecodeUtf8 . LB.toStrict $ J.encode defaultAppSettings {AS.webrtcICEServers = Just ["non-default.value.com"]}
|
||||
-- Long command echo may be split by virtual terminal getDiff;
|
||||
-- skip non-matching lines to find the expected response, then drain artifacts
|
||||
sendFindResponse cmd resp = do
|
||||
alice `send` cmd
|
||||
let go 0 = error $ "expected but not received: " <> resp
|
||||
go n = do
|
||||
line <- getTermLine alice
|
||||
unless (line == resp) $ go (n - 1)
|
||||
go (50 :: Int)
|
||||
let drain = timeout 50000 (getTermLine alice) >>= mapM_ (\_ -> drain)
|
||||
drain
|
||||
-- app-provided defaults
|
||||
alice ##> ("/_get app settings " <> settingsApp)
|
||||
alice <## ("app settings: " <> settingsApp)
|
||||
sendFindResponse ("/_get app settings " <> settingsApp) ("app settings: " <> settingsApp)
|
||||
-- parser defaults fallback
|
||||
alice ##> "/_get app settings"
|
||||
alice <## ("app settings: " <> settings)
|
||||
-- store
|
||||
alice ##> ("/_save app settings " <> settingsApp)
|
||||
alice <## "ok"
|
||||
sendFindResponse ("/_save app settings " <> settingsApp) "ok"
|
||||
-- read back
|
||||
alice ##> "/_get app settings"
|
||||
alice <## ("app settings: " <> settingsApp)
|
||||
|
||||
Reference in New Issue
Block a user