From b001342c1ff7d199a4165ba86b1b903c0558a9f0 Mon Sep 17 00:00:00 2001 From: thomasjm Date: Mon, 10 Jun 2024 20:10:48 -0700 Subject: [PATCH] demo-webdriver-pool working now --- demos/demo-webdriver-pool/app/Main.hs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/demos/demo-webdriver-pool/app/Main.hs b/demos/demo-webdriver-pool/app/Main.hs index 1847a93..0929619 100644 --- a/demos/demo-webdriver-pool/app/Main.hs +++ b/demos/demo-webdriver-pool/app/Main.hs @@ -40,13 +40,12 @@ introduceWebDriverPool :: forall m context. ( MonadUnliftIO m, MonadBaseControl IO m, MonadMask m , HasBaseContext context, HasSomeCommandLineOptions context, HasBrowserDependencies context, HasFile context "java", HasFile context "selenium.jar" ) => Int -> WdOptions -> SpecFree (LabelValue "webDriverPool" (Pool WebDriver) :> context) m () -> SpecFree context m () -introduceWebDriverPool poolSize wdOptions' = introduce "Introduce webdriver pool" webDriverPool alloc cleanup - where - alloc = do - wdOptions <- addCommandLineOptionsToWdOptions <$> getSomeCommandLineOptions <*> pure wdOptions' - newPool =<< mkSafeDefaultPoolConfig (runNoLoggingT $ allocateWebDriver wdOptions) cleanupWebDriver 30.0 poolSize - cleanup = liftIO . destroyAllResources +introduceWebDriverPool poolSize wdOptions' = introduceWith "Introduce webdriver pool" webDriverPool $ \action -> do + wdOptions <- addCommandLineOptionsToWdOptions <$> getSomeCommandLineOptions <*> pure wdOptions' + bracket (newPool =<< mkSafeDefaultPoolConfig (allocateWebDriver wdOptions) cleanupWebDriver 30.0 poolSize) destroyAllResources $ \pool -> + void $ action pool + where -- Based on https://hackage.haskell.org/package/unliftio-pool-0.4.2.0/docs/UnliftIO-Pool.html#v:mkDefaultPoolConfig -- Due to https://github.com/scrive/pool/issues/31 mkSafeDefaultPoolConfig :: forall n a. MonadUnliftIO n => n a -> (a -> n ()) -> Double -> Int -> n (PoolConfig a) @@ -74,7 +73,7 @@ tests = introduceBinaryViaNixPackage @"java" "jre" $ introduceBrowserDependenciesViaNix $ introduceWebDriverPool 4 defaultWdOptions $ - -- parallel $ + parallel $ replicateM_ 20 $ claimWebdriver $ it "opens Google" $ withSession1 $ openPage "http://www.google.com" where