Skip to content

fix: Fix race condition on WaiSpec test (Copilot 🤖) #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
{
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
};

outputs = { self, flake-utils, nixpkgs }:
outputs =
{
self,
flake-utils,
nixpkgs,
}:
flake-utils.lib.simpleFlake {
inherit self nixpkgs;
name = "rollbar-haskell";
Expand Down
5 changes: 5 additions & 0 deletions rollbar-wai/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ All notable changes to this project will be documented in this file.
- Changed `text` dependency upper bound: we now support `text-2.0.X.X`.

## Unreleased changes

### Changed
- `rollbarOnExceptionWith` now takes a fork function of type `IO () -> IO ()`.
- All tests are now synchronous and no longer use `threadDelay`.
- Updated `rollbarOnException` and all usages to match the new signature.
2 changes: 1 addition & 1 deletion rollbar-wai/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: rollbar-wai
version: 1.1.1
version: 1.2.0
github: "stackbuilders/rollbar-haskell"
license: MIT
author: "Stack Builders Inc."
Expand Down
2 changes: 1 addition & 1 deletion rollbar-wai/rollbar-wai.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.12
-- see: https://github.com/sol/hpack

name: rollbar-wai
version: 1.1.1
version: 1.2.0
synopsis: Provides error reporting capabilities to WAI based applications through Rollbar API.

description: Please see the README on GitHub at
Expand Down
9 changes: 5 additions & 4 deletions rollbar-wai/src/Rollbar/Wai.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,22 @@ rollbarOnException
-> Maybe W.Request
-> SomeException
-> m ()
rollbarOnException = rollbarOnExceptionWith (void . createItem)
rollbarOnException = rollbarOnExceptionWith (void . forkIO) (void . createItem)

-- | Similar to 'rollbarOnExceptionWith', but it allows customize the function
-- used to send the 'Item' to Rollbar.
--
-- @since 0.1.0
rollbarOnExceptionWith
:: MonadIO m
=> (Item -> Rollbar ())
=> (IO () -> IO ()) -- ^ fork function (returns unit)
-> (Item -> Rollbar ())
-> Settings
-> Maybe W.Request
-> SomeException
-> m ()
rollbarOnExceptionWith f settings waiRequest ex =
void $ liftIO $ forkIO $ runRollbar settings $ do
rollbarOnExceptionWith fork f settings waiRequest ex =
void $ liftIO $ fork $ runRollbar settings $ do
item <- mkItem $ PayloadTrace $ Trace [] $ mkException ex
request <- mapM mkRequest waiRequest
f item
Expand Down
5 changes: 1 addition & 4 deletions rollbar-wai/test/Rollbar/WaiSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import qualified Data.Text as T
import qualified Network.Wai as W
import qualified Network.Wai.Handler.Warp as W

import Control.Concurrent (threadDelay)
import Control.Monad (join)
import Control.Monad.IO.Class
import Data.Aeson
Expand All @@ -33,7 +32,6 @@ spec = before getSettingsAndItemRef $
(req GET url NoReqBody bsResponse $ port warpPort)
responseStatusCode response `shouldBe` 200
responseBody response `shouldBe` "OK"
threadDelay 500
readIORef itemRef `shouldReturn` Nothing

context "when the response status code is not 200" $
Expand All @@ -44,7 +42,6 @@ spec = before getSettingsAndItemRef $
(defaultHttpConfig { httpConfigCheckResponse = \_ _ _ -> Nothing })
(req GET url NoReqBody bsResponse $ port warpPort)
response `shouldBe` "Something went wrong"
threadDelay 500
let portAsText = T.pack $ show warpPort
join . fmap itemRequest <$> readIORef itemRef `shouldReturn` Just
( Request
Expand Down Expand Up @@ -75,7 +72,7 @@ withApp
-> IO a
withApp f (settings, itemRef) = do
let waiSettings = W.setOnException
(rollbarOnExceptionWith (createItemFake itemRef) settings)
(rollbarOnExceptionWith id (createItemFake itemRef) settings)
W.defaultSettings
W.withApplicationSettings waiSettings (return app) $ f itemRef

Expand Down
4 changes: 2 additions & 2 deletions rollbar-yesod/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: rollbar-yesod
version: 1.1.1
version: 1.1.2
github: "stackbuilders/rollbar-haskell"
license: MIT
author: "Stack Builders Inc."
Expand Down Expand Up @@ -41,7 +41,7 @@ library:
source-dirs: src
dependencies:
- rollbar-client >= 1.0 && < 2
- rollbar-wai >= 1.0 && < 2
- rollbar-wai >= 1.2 && < 2
- unliftio >= 0.2 && < 1
- wai >= 3.2 && < 4
- yesod-core >= 1.6 && < 2
Expand Down
4 changes: 2 additions & 2 deletions rollbar-yesod/rollbar-yesod.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.12
-- see: https://github.com/sol/hpack

name: rollbar-yesod
version: 1.1.1
version: 1.1.2
synopsis: Provides error reporting capabilities to Yesod applications through Rollbar API.

description: Please see the README on GitHub at
Expand Down Expand Up @@ -45,7 +45,7 @@ library
build-depends:
base >=4.18 && <5
, rollbar-client >=1.0 && <2
, rollbar-wai >=1.0 && <2
, rollbar-wai >=1.2 && <2
, unliftio >=0.2 && <1
, wai >=3.2 && <4
, yesod-core >=1.6 && <2
Expand Down
3 changes: 2 additions & 1 deletion rollbar-yesod/src/Rollbar/Yesod.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module Rollbar.Yesod

import qualified Network.Wai as W

import Control.Concurrent (forkIO)
import Control.Exception (Exception(..), SomeException)
import Control.Monad (unless, void)
import Rollbar.Client
Expand All @@ -40,7 +41,7 @@ rollbarYesodMiddleware
=> m a
-> m a
rollbarYesodMiddleware = rollbarYesodMiddlewareWith $ \settings request ex ->
rollbarOnExceptionWith handler settings (Just request) ex
rollbarOnExceptionWith (void . forkIO) handler settings (Just request) ex
where
handler item = void $ createItem item { itemFramework = Just "yesod" }

Expand Down
Loading