use option in test

This commit is contained in:
Evgeny Poberezkin committed 2024-12-28 20:00:44 +00:00
1 parent af21c9779a
commit f2568b65c0
4 files changed
+11 -11

No files matched your search

+2 -2
View File
@@ -34,14 +34,14 @@ import Text.Read (readMaybe)
import UnliftIO.Async
simplexChatCore :: ChatConfig -> ChatOpts -> (User -> ChatController -> IO ()) -> IO ()
simplexChatCore cfg@ChatConfig {confirmMigrations, testView} opts@ChatOpts {coreOptions = CoreChatOpts {dbFilePrefix, dbKey, logAgent, yesToUpMigrations, vaccumOnMigration}} chat =
simplexChatCore cfg@ChatConfig {confirmMigrations, testView} opts@ChatOpts {coreOptions = CoreChatOpts {dbFilePrefix, dbKey, logAgent, yesToUpMigrations, vacuumOnMigration}} chat =
case logAgent of
Just level -> do
setLogLevel level
withGlobalLogging logCfg initRun
_ -> initRun
where
initRun = createChatDatabase dbFilePrefix dbKey False confirm' vaccumOnMigration >>= either exit run
initRun = createChatDatabase dbFilePrefix dbKey False confirm' vacuumOnMigration >>= either exit run
confirm' = if confirmMigrations == MCConsole && yesToUpMigrations then MCYesUp else confirmMigrations
exit e = do
putStrLn $ "Error opening database: " <> show e
+2 -2
View File
@@ -202,7 +202,7 @@ mobileChatOpts dbFilePrefix =
tbqSize = 1024,
highlyAvailable = False,
yesToUpMigrations = False,
vaccumOnMigration = True
vacuumOnMigration = True
},
deviceName = Nothing,
chatCmd = "",
@@ -247,7 +247,7 @@ chatMigrateInitKey dbFilePrefix dbKey keepKey confirm backgroundMode = runExcept
newChatController db user_ defaultMobileConfig opts backgroundMode
migrate createStore dbFile confirmMigrations =
ExceptT $
(first (DBMErrorMigration dbFile) <$> createStore dbFile dbKey keepKey confirmMigrations (vaccumOnMigration $ coreOptions opts))
(first (DBMErrorMigration dbFile) <$> createStore dbFile dbKey keepKey confirmMigrations (vacuumOnMigration $ coreOptions opts))
`catch` (pure . checkDBError)
`catchAll` (pure . dbError)
where
+2 -2
View File
@@ -67,7 +67,7 @@ data CoreChatOpts = CoreChatOpts
tbqSize :: Natural,
highlyAvailable :: Bool,
yesToUpMigrations :: Bool,
vaccumOnMigration :: Bool
vacuumOnMigration :: Bool
}
data ChatCmdLog = CCLAll | CCLMessages | CCLNone
@@ -272,7 +272,7 @@ coreChatOptsP appDir defaultDbFileName = do
tbqSize,
highlyAvailable,
yesToUpMigrations,
vaccumOnMigration = not disableVacuum
vacuumOnMigration = not disableVacuum
}
where
useTcpTimeout p t = 1000000 * if t > 0 then t else maybe 7 (const 15) p
+5 -5
View File
@@ -107,7 +107,7 @@ testCoreOpts =
tbqSize = 16,
highlyAvailable = False,
yesToUpMigrations = False,
vaccumOnMigration = True
vacuumOnMigration = True
}
getTestOpts :: Bool -> ScrubbedBytes -> ChatOpts
@@ -248,15 +248,15 @@ groupLinkViaContactVRange :: VersionRangeChat
groupLinkViaContactVRange = mkVersionRange (VersionChat 1) (VersionChat 2)
createTestChat :: FilePath -> ChatConfig -> ChatOpts -> String -> Profile -> IO TestCC
createTestChat tmp cfg opts@ChatOpts {coreOptions = CoreChatOpts {dbKey}} dbPrefix profile = do
Right db@ChatDatabase {chatStore, agentStore} <- createChatDatabase (tmp </> dbPrefix) dbKey False MCError True
createTestChat tmp cfg opts@ChatOpts {coreOptions = CoreChatOpts {dbKey, vacuumOnMigration}} dbPrefix profile = do
Right db@ChatDatabase {chatStore, agentStore} <- createChatDatabase (tmp </> dbPrefix) dbKey False MCError vacuumOnMigration
withTransaction agentStore (`DB.execute_` "INSERT INTO users (user_id) VALUES (1);")
Right user <- withTransaction chatStore $ \db' -> runExceptT $ createUserRecord db' (AgentUserId 1) profile True
startTestChat_ db cfg opts user
startTestChat :: FilePath -> ChatConfig -> ChatOpts -> String -> IO TestCC
startTestChat tmp cfg opts@ChatOpts {coreOptions = CoreChatOpts {dbKey}} dbPrefix = do
Right db@ChatDatabase {chatStore} <- createChatDatabase (tmp </> dbPrefix) dbKey False MCError True
startTestChat tmp cfg opts@ChatOpts {coreOptions = CoreChatOpts {dbKey, vacuumOnMigration}} dbPrefix = do
Right db@ChatDatabase {chatStore} <- createChatDatabase (tmp </> dbPrefix) dbKey False MCError vacuumOnMigration
Just user <- find activeUser <$> withTransaction chatStore getUsers
startTestChat_ db cfg opts user