I need to check out a variety of functions that access the database (via Persistent). Although I can do this using monadicIO and withSqlitePool , it will lead to inefficient tests. Each test, rather than the property, but the test, create and destroy database pool. How to prevent this?
Important: Forget about the effectiveness, or elegance. I was not even able to create the types of QuickCheck and Persistent to create.
instance (Monad a) => MonadThrow (PropertyM a) instance (MonadThrow a) => MonadCatch (PropertyM a) type NwApp = SqlPersistT IO prop_childCreation :: PropertyM NwApp Bool prop_childCreation = do uid <- pick $ UserKey <$> arbitrary lid <- pick $ LogKey <$> arbitrary gid <- pick $ Aria2Gid <$> arbitrary let createDownload_ = createDownload gid lid uid [] (Entity pid _) <- run $ createDownload_ Nothing dstatus <- pick arbitrary parent <- run $ updateGet pid [DownloadStatus =. dstatus] let test = do (Entity cid child) <- run $ createDownload_ (Just pid) case (parent ^. status, child ^. status) of (DownloadComplete ChildrenComplete, DownloadComplete ChildrenNone) -> return True (DownloadComplete ChildrenIncomplete, DownloadIncomplete) -> return True _ -> return False test `catches` [ Handler (\ (e :: SanityException) -> return True), Handler (\ (e :: SomeException) -> return False) ] -- How do I write this function? runTests = monadicIO $ runSqlite ":memory:" $ do -- whatever I do, this function fails to typecheck (PropertyM a) instance (Monad a) => MonadThrow (PropertyM a) instance (MonadThrow a) => MonadCatch (PropertyM a) type NwApp = SqlPersistT IO prop_childCreation :: PropertyM NwApp Bool prop_childCreation = do uid <- pick $ UserKey <$> arbitrary lid <- pick $ LogKey <$> arbitrary gid <- pick $ Aria2Gid <$> arbitrary let createDownload_ = createDownload gid lid uid [] (Entity pid _) <- run $ createDownload_ Nothing dstatus <- pick arbitrary parent <- run $ updateGet pid [DownloadStatus =. dstatus] let test = do (Entity cid child) <- run $ createDownload_ (Just pid) case (parent ^. status, child ^. status) of (DownloadComplete ChildrenComplete, DownloadComplete ChildrenNone) -> return True (DownloadComplete ChildrenIncomplete, DownloadIncomplete) -> return True _ -> return False test `catches` [ Handler (\ (e :: SanityException) -> return True), Handler (\ (e :: SomeException) -> return False) ] -- How do I write this function? runTests = monadicIO $ runSqlite ":memory:" $ do -- whatever I do, this function fails to typecheck (PropertyM a) instance (Monad a) => MonadThrow (PropertyM a) instance (MonadThrow a) => MonadCatch (PropertyM a) type NwApp = SqlPersistT IO prop_childCreation :: PropertyM NwApp Bool prop_childCreation = do uid <- pick $ UserKey <$> arbitrary lid <- pick $ LogKey <$> arbitrary gid <- pick $ Aria2Gid <$> arbitrary let createDownload_ = createDownload gid lid uid [] (Entity pid _) <- run $ createDownload_ Nothing dstatus <- pick arbitrary parent <- run $ updateGet pid [DownloadStatus =. dstatus] let test = do (Entity cid child) <- run $ createDownload_ (Just pid) case (parent ^. status, child ^. status) of (DownloadComplete ChildrenComplete, DownloadComplete ChildrenNone) -> return True (DownloadComplete ChildrenIncomplete, DownloadIncomplete) -> return True _ -> return False test `catches` [ Handler (\ (e :: SanityException) -> return True), Handler (\ (e :: SomeException) -> return False) ] -- How do I write this function? runTests = monadicIO $ runSqlite ":memory:" $ do -- whatever I do, this function fails to typecheck > arbitrary instance (Monad a) => MonadThrow (PropertyM a) instance (MonadThrow a) => MonadCatch (PropertyM a) type NwApp = SqlPersistT IO prop_childCreation :: PropertyM NwApp Bool prop_childCreation = do uid <- pick $ UserKey <$> arbitrary lid <- pick $ LogKey <$> arbitrary gid <- pick $ Aria2Gid <$> arbitrary let createDownload_ = createDownload gid lid uid [] (Entity pid _) <- run $ createDownload_ Nothing dstatus <- pick arbitrary parent <- run $ updateGet pid [DownloadStatus =. dstatus] let test = do (Entity cid child) <- run $ createDownload_ (Just pid) case (parent ^. status, child ^. status) of (DownloadComplete ChildrenComplete, DownloadComplete ChildrenNone) -> return True (DownloadComplete ChildrenIncomplete, DownloadIncomplete) -> return True _ -> return False test `catches` [ Handler (\ (e :: SanityException) -> return True), Handler (\ (e :: SomeException) -> return False) ] -- How do I write this function? runTests = monadicIO $ runSqlite ":memory:" $ do -- whatever I do, this function fails to typecheck > arbitrary instance (Monad a) => MonadThrow (PropertyM a) instance (MonadThrow a) => MonadCatch (PropertyM a) type NwApp = SqlPersistT IO prop_childCreation :: PropertyM NwApp Bool prop_childCreation = do uid <- pick $ UserKey <$> arbitrary lid <- pick $ LogKey <$> arbitrary gid <- pick $ Aria2Gid <$> arbitrary let createDownload_ = createDownload gid lid uid [] (Entity pid _) <- run $ createDownload_ Nothing dstatus <- pick arbitrary parent <- run $ updateGet pid [DownloadStatus =. dstatus] let test = do (Entity cid child) <- run $ createDownload_ (Just pid) case (parent ^. status, child ^. status) of (DownloadComplete ChildrenComplete, DownloadComplete ChildrenNone) -> return True (DownloadComplete ChildrenIncomplete, DownloadIncomplete) -> return True _ -> return False test `catches` [ Handler (\ (e :: SanityException) -> return True), Handler (\ (e :: SomeException) -> return False) ] -- How do I write this function? runTests = monadicIO $ runSqlite ":memory:" $ do -- whatever I do, this function fails to typecheck > arbitrary instance (Monad a) => MonadThrow (PropertyM a) instance (MonadThrow a) => MonadCatch (PropertyM a) type NwApp = SqlPersistT IO prop_childCreation :: PropertyM NwApp Bool prop_childCreation = do uid <- pick $ UserKey <$> arbitrary lid <- pick $ LogKey <$> arbitrary gid <- pick $ Aria2Gid <$> arbitrary let createDownload_ = createDownload gid lid uid [] (Entity pid _) <- run $ createDownload_ Nothing dstatus <- pick arbitrary parent <- run $ updateGet pid [DownloadStatus =. dstatus] let test = do (Entity cid child) <- run $ createDownload_ (Just pid) case (parent ^. status, child ^. status) of (DownloadComplete ChildrenComplete, DownloadComplete ChildrenNone) -> return True (DownloadComplete ChildrenIncomplete, DownloadIncomplete) -> return True _ -> return False test `catches` [ Handler (\ (e :: SanityException) -> return True), Handler (\ (e :: SomeException) -> return False) ] -- How do I write this function? runTests = monadicIO $ runSqlite ":memory:" $ do -- whatever I do, this function fails to typecheck ] instance (Monad a) => MonadThrow (PropertyM a) instance (MonadThrow a) => MonadCatch (PropertyM a) type NwApp = SqlPersistT IO prop_childCreation :: PropertyM NwApp Bool prop_childCreation = do uid <- pick $ UserKey <$> arbitrary lid <- pick $ LogKey <$> arbitrary gid <- pick $ Aria2Gid <$> arbitrary let createDownload_ = createDownload gid lid uid [] (Entity pid _) <- run $ createDownload_ Nothing dstatus <- pick arbitrary parent <- run $ updateGet pid [DownloadStatus =. dstatus] let test = do (Entity cid child) <- run $ createDownload_ (Just pid) case (parent ^. status, child ^. status) of (DownloadComplete ChildrenComplete, DownloadComplete ChildrenNone) -> return True (DownloadComplete ChildrenIncomplete, DownloadIncomplete) -> return True _ -> return False test `catches` [ Handler (\ (e :: SanityException) -> return True), Handler (\ (e :: SomeException) -> return False) ] -- How do I write this function? runTests = monadicIO $ runSqlite ":memory:" $ do -- whatever I do, this function fails to typecheck $ createDownload_ Nothing instance (Monad a) => MonadThrow (PropertyM a) instance (MonadThrow a) => MonadCatch (PropertyM a) type NwApp = SqlPersistT IO prop_childCreation :: PropertyM NwApp Bool prop_childCreation = do uid <- pick $ UserKey <$> arbitrary lid <- pick $ LogKey <$> arbitrary gid <- pick $ Aria2Gid <$> arbitrary let createDownload_ = createDownload gid lid uid [] (Entity pid _) <- run $ createDownload_ Nothing dstatus <- pick arbitrary parent <- run $ updateGet pid [DownloadStatus =. dstatus] let test = do (Entity cid child) <- run $ createDownload_ (Just pid) case (parent ^. status, child ^. status) of (DownloadComplete ChildrenComplete, DownloadComplete ChildrenNone) -> return True (DownloadComplete ChildrenIncomplete, DownloadIncomplete) -> return True _ -> return False test `catches` [ Handler (\ (e :: SanityException) -> return True), Handler (\ (e :: SomeException) -> return False) ] -- How do I write this function? runTests = monadicIO $ runSqlite ":memory:" $ do -- whatever I do, this function fails to typecheck DownloadStatus =. instance (Monad a) => MonadThrow (PropertyM a) instance (MonadThrow a) => MonadCatch (PropertyM a) type NwApp = SqlPersistT IO prop_childCreation :: PropertyM NwApp Bool prop_childCreation = do uid <- pick $ UserKey <$> arbitrary lid <- pick $ LogKey <$> arbitrary gid <- pick $ Aria2Gid <$> arbitrary let createDownload_ = createDownload gid lid uid [] (Entity pid _) <- run $ createDownload_ Nothing dstatus <- pick arbitrary parent <- run $ updateGet pid [DownloadStatus =. dstatus] let test = do (Entity cid child) <- run $ createDownload_ (Just pid) case (parent ^. status, child ^. status) of (DownloadComplete ChildrenComplete, DownloadComplete ChildrenNone) -> return True (DownloadComplete ChildrenIncomplete, DownloadIncomplete) -> return True _ -> return False test `catches` [ Handler (\ (e :: SanityException) -> return True), Handler (\ (e :: SomeException) -> return False) ] -- How do I write this function? runTests = monadicIO $ runSqlite ":memory:" $ do -- whatever I do, this function fails to typecheck $ createDownload_ (Just pid) instance (Monad a) => MonadThrow (PropertyM a) instance (MonadThrow a) => MonadCatch (PropertyM a) type NwApp = SqlPersistT IO prop_childCreation :: PropertyM NwApp Bool prop_childCreation = do uid <- pick $ UserKey <$> arbitrary lid <- pick $ LogKey <$> arbitrary gid <- pick $ Aria2Gid <$> arbitrary let createDownload_ = createDownload gid lid uid [] (Entity pid _) <- run $ createDownload_ Nothing dstatus <- pick arbitrary parent <- run $ updateGet pid [DownloadStatus =. dstatus] let test = do (Entity cid child) <- run $ createDownload_ (Just pid) case (parent ^. status, child ^. status) of (DownloadComplete ChildrenComplete, DownloadComplete ChildrenNone) -> return True (DownloadComplete ChildrenIncomplete, DownloadIncomplete) -> return True _ -> return False test `catches` [ Handler (\ (e :: SanityException) -> return True), Handler (\ (e :: SomeException) -> return False) ] -- How do I write this function? runTests = monadicIO $ runSqlite ":memory:" $ do -- whatever I do, this function fails to typecheck ^. status) of instance (Monad a) => MonadThrow (PropertyM a) instance (MonadThrow a) => MonadCatch (PropertyM a) type NwApp = SqlPersistT IO prop_childCreation :: PropertyM NwApp Bool prop_childCreation = do uid <- pick $ UserKey <$> arbitrary lid <- pick $ LogKey <$> arbitrary gid <- pick $ Aria2Gid <$> arbitrary let createDownload_ = createDownload gid lid uid [] (Entity pid _) <- run $ createDownload_ Nothing dstatus <- pick arbitrary parent <- run $ updateGet pid [DownloadStatus =. dstatus] let test = do (Entity cid child) <- run $ createDownload_ (Just pid) case (parent ^. status, child ^. status) of (DownloadComplete ChildrenComplete, DownloadComplete ChildrenNone) -> return True (DownloadComplete ChildrenIncomplete, DownloadIncomplete) -> return True _ -> return False test `catches` [ Handler (\ (e :: SanityException) -> return True), Handler (\ (e :: SomeException) -> return False) ] -- How do I write this function? runTests = monadicIO $ runSqlite ":memory:" $ do -- whatever I do, this function fails to typecheck > return True instance (Monad a) => MonadThrow (PropertyM a) instance (MonadThrow a) => MonadCatch (PropertyM a) type NwApp = SqlPersistT IO prop_childCreation :: PropertyM NwApp Bool prop_childCreation = do uid <- pick $ UserKey <$> arbitrary lid <- pick $ LogKey <$> arbitrary gid <- pick $ Aria2Gid <$> arbitrary let createDownload_ = createDownload gid lid uid [] (Entity pid _) <- run $ createDownload_ Nothing dstatus <- pick arbitrary parent <- run $ updateGet pid [DownloadStatus =. dstatus] let test = do (Entity cid child) <- run $ createDownload_ (Just pid) case (parent ^. status, child ^. status) of (DownloadComplete ChildrenComplete, DownloadComplete ChildrenNone) -> return True (DownloadComplete ChildrenIncomplete, DownloadIncomplete) -> return True _ -> return False test `catches` [ Handler (\ (e :: SanityException) -> return True), Handler (\ (e :: SomeException) -> return False) ] -- How do I write this function? runTests = monadicIO $ runSqlite ":memory:" $ do -- whatever I do, this function fails to typecheck return True instance (Monad a) => MonadThrow (PropertyM a) instance (MonadThrow a) => MonadCatch (PropertyM a) type NwApp = SqlPersistT IO prop_childCreation :: PropertyM NwApp Bool prop_childCreation = do uid <- pick $ UserKey <$> arbitrary lid <- pick $ LogKey <$> arbitrary gid <- pick $ Aria2Gid <$> arbitrary let createDownload_ = createDownload gid lid uid [] (Entity pid _) <- run $ createDownload_ Nothing dstatus <- pick arbitrary parent <- run $ updateGet pid [DownloadStatus =. dstatus] let test = do (Entity cid child) <- run $ createDownload_ (Just pid) case (parent ^. status, child ^. status) of (DownloadComplete ChildrenComplete, DownloadComplete ChildrenNone) -> return True (DownloadComplete ChildrenIncomplete, DownloadIncomplete) -> return True _ -> return False test `catches` [ Handler (\ (e :: SanityException) -> return True), Handler (\ (e :: SomeException) -> return False) ] -- How do I write this function? runTests = monadicIO $ runSqlite ":memory:" $ do -- whatever I do, this function fails to typecheck -> return True), instance (Monad a) => MonadThrow (PropertyM a) instance (MonadThrow a) => MonadCatch (PropertyM a) type NwApp = SqlPersistT IO prop_childCreation :: PropertyM NwApp Bool prop_childCreation = do uid <- pick $ UserKey <$> arbitrary lid <- pick $ LogKey <$> arbitrary gid <- pick $ Aria2Gid <$> arbitrary let createDownload_ = createDownload gid lid uid [] (Entity pid _) <- run $ createDownload_ Nothing dstatus <- pick arbitrary parent <- run $ updateGet pid [DownloadStatus =. dstatus] let test = do (Entity cid child) <- run $ createDownload_ (Just pid) case (parent ^. status, child ^. status) of (DownloadComplete ChildrenComplete, DownloadComplete ChildrenNone) -> return True (DownloadComplete ChildrenIncomplete, DownloadIncomplete) -> return True _ -> return False test `catches` [ Handler (\ (e :: SanityException) -> return True), Handler (\ (e :: SomeException) -> return False) ] -- How do I write this function? runTests = monadicIO $ runSqlite ":memory:" $ do -- whatever I do, this function fails to typecheck -> return False) instance (Monad a) => MonadThrow (PropertyM a) instance (MonadThrow a) => MonadCatch (PropertyM a) type NwApp = SqlPersistT IO prop_childCreation :: PropertyM NwApp Bool prop_childCreation = do uid <- pick $ UserKey <$> arbitrary lid <- pick $ LogKey <$> arbitrary gid <- pick $ Aria2Gid <$> arbitrary let createDownload_ = createDownload gid lid uid [] (Entity pid _) <- run $ createDownload_ Nothing dstatus <- pick arbitrary parent <- run $ updateGet pid [DownloadStatus =. dstatus] let test = do (Entity cid child) <- run $ createDownload_ (Just pid) case (parent ^. status, child ^. status) of (DownloadComplete ChildrenComplete, DownloadComplete ChildrenNone) -> return True (DownloadComplete ChildrenIncomplete, DownloadIncomplete) -> return True _ -> return False test `catches` [ Handler (\ (e :: SanityException) -> return True), Handler (\ (e :: SomeException) -> return False) ] -- How do I write this function? runTests = monadicIO $ runSqlite ":memory:" $ do -- whatever I do, this function fails to typecheck :" $ do instance (Monad a) => MonadThrow (PropertyM a) instance (MonadThrow a) => MonadCatch (PropertyM a) type NwApp = SqlPersistT IO prop_childCreation :: PropertyM NwApp Bool prop_childCreation = do uid <- pick $ UserKey <$> arbitrary lid <- pick $ LogKey <$> arbitrary gid <- pick $ Aria2Gid <$> arbitrary let createDownload_ = createDownload gid lid uid [] (Entity pid _) <- run $ createDownload_ Nothing dstatus <- pick arbitrary parent <- run $ updateGet pid [DownloadStatus =. dstatus] let test = do (Entity cid child) <- run $ createDownload_ (Just pid) case (parent ^. status, child ^. status) of (DownloadComplete ChildrenComplete, DownloadComplete ChildrenNone) -> return True (DownloadComplete ChildrenIncomplete, DownloadIncomplete) -> return True _ -> return False test `catches` [ Handler (\ (e :: SanityException) -> return True), Handler (\ (e :: SomeException) -> return False) ] -- How do I write this function? runTests = monadicIO $ runSqlite ":memory:" $ do -- whatever I do, this function fails to typecheck