Skip to content
Merged
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
20 changes: 20 additions & 0 deletions .ormolu
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
infixr 0 <|
infixl 0 |>
infixr 2 ||
infixr 3 &&
infix 4 ==
infix 4 /=
infix 4 <
infix 4 >
infix 4 <=
infix 4 >=
infixr 5 ++
infixl 6 +
infixl 6 -
infixl 7 *
infixl 7 /
infixl 7 //
infixr 8 ^
infixl 9 <<
infixr 9 >>

207 changes: 100 additions & 107 deletions nri-env-parser/tests/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,57 +21,54 @@ tests =
"Environment"
[ describe
"enum"
[ test "should decode to the correct value"
<| \() ->
Environment.decodePairs
( Environment.variable
Environment.Variable
{ Environment.name = "TEST",
Environment.description = "test",
Environment.defaultValue = "A"
}
( Environment.enum
[ ("A", A),
("B", B)
]
)
)
(Dict.singleton "TEST" "A")
|> Expect.equal (Ok A),
test "should error if the value is not in the enum"
<| \() ->
Environment.decodePairs
( Environment.variable
Environment.Variable
{ Environment.name = "TEST",
Environment.description = "test",
Environment.defaultValue = "A"
}
( Environment.enum
[ ("A", A),
("B", B)
]
)
)
(Dict.singleton "TEST" "C")
|> Expect.equal (Err "Parsing TEST failed: Unknown option: C ( A, B )"),
test "should use the default value if the key is not present"
<| \() ->
Environment.decodePairs
( Environment.variable
Environment.Variable
{ Environment.name = "TEST",
Environment.description = "test",
Environment.defaultValue = "B"
}
( Environment.enum
[ ("A", A),
("B", B)
]
)
)
(Dict.empty)
|> Expect.equal (Ok B)
[ test "should decode to the correct value" <| \() ->
Environment.decodePairs
( Environment.variable
Environment.Variable
{ Environment.name = "TEST",
Environment.description = "test",
Environment.defaultValue = "A"
}
( Environment.enum
[ ("A", A),
("B", B)
]
)
)
(Dict.singleton "TEST" "A")
|> Expect.equal (Ok A),
test "should error if the value is not in the enum" <| \() ->
Environment.decodePairs
( Environment.variable
Environment.Variable
{ Environment.name = "TEST",
Environment.description = "test",
Environment.defaultValue = "A"
}
( Environment.enum
[ ("A", A),
("B", B)
]
)
)
(Dict.singleton "TEST" "C")
|> Expect.equal (Err "Parsing TEST failed: Unknown option: C ( A, B )"),
test "should use the default value if the key is not present" <| \() ->
Environment.decodePairs
( Environment.variable
Environment.Variable
{ Environment.name = "TEST",
Environment.description = "test",
Environment.defaultValue = "B"
}
( Environment.enum
[ ("A", A),
("B", B)
]
)
)
(Dict.empty)
|> Expect.equal (Ok B)
],
let enumDecoder =
Environment.variable
Expand Down Expand Up @@ -138,61 +135,57 @@ tests =
],
describe
"variableWithOptionalPrefix"
[ test "Should use the prefixed value if available"
<| \() ->
Environment.decodePairs
( Environment.variableWithOptionalPrefix
"PREFIX_"
Environment.Variable
{ Environment.name = "TEST",
Environment.description = "test",
Environment.defaultValue = "default"
}
Environment.text
)
(Dict.singleton "PREFIX_TEST" "prefixed")
|> Expect.equal (Ok "prefixed"),
test "Should use the prefixed value if both prefixed and unprefixed are available"
<| \() ->
Environment.decodePairs
( Environment.variableWithOptionalPrefix
"PREFIX_"
Environment.Variable
{ Environment.name = "TEST",
Environment.description = "test",
Environment.defaultValue = "default"
}
Environment.text
)
(Dict.fromList [("PREFIX_TEST", "prefixed"), ("TEST", "unprefixed")])
|> Expect.equal (Ok "prefixed"),
test "Should use the unprefixed value if only unprefixed is available"
<| \() ->
Environment.decodePairs
( Environment.variableWithOptionalPrefix
"PREFIX_"
Environment.Variable
{ Environment.name = "TEST",
Environment.description = "test",
Environment.defaultValue = "default"
}
Environment.text
)
(Dict.singleton "TEST" "unprefixed")
|> Expect.equal (Ok "unprefixed"),
test "Should use the default value if prefixed nor unprefixed is available"
<| \() ->
Environment.decodePairs
( Environment.variableWithOptionalPrefix
"PREFIX_"
Environment.Variable
{ Environment.name = "TEST",
Environment.description = "test",
Environment.defaultValue = "default"
}
Environment.text
)
Dict.empty
|> Expect.equal (Ok "default")
[ test "Should use the prefixed value if available" <| \() ->
Environment.decodePairs
( Environment.variableWithOptionalPrefix
"PREFIX_"
Environment.Variable
{ Environment.name = "TEST",
Environment.description = "test",
Environment.defaultValue = "default"
}
Environment.text
)
(Dict.singleton "PREFIX_TEST" "prefixed")
|> Expect.equal (Ok "prefixed"),
test "Should use the prefixed value if both prefixed and unprefixed are available" <| \() ->
Environment.decodePairs
( Environment.variableWithOptionalPrefix
"PREFIX_"
Environment.Variable
{ Environment.name = "TEST",
Environment.description = "test",
Environment.defaultValue = "default"
}
Environment.text
)
(Dict.fromList [("PREFIX_TEST", "prefixed"), ("TEST", "unprefixed")])
|> Expect.equal (Ok "prefixed"),
test "Should use the unprefixed value if only unprefixed is available" <| \() ->
Environment.decodePairs
( Environment.variableWithOptionalPrefix
"PREFIX_"
Environment.Variable
{ Environment.name = "TEST",
Environment.description = "test",
Environment.defaultValue = "default"
}
Environment.text
)
(Dict.singleton "TEST" "unprefixed")
|> Expect.equal (Ok "unprefixed"),
test "Should use the default value if prefixed nor unprefixed is available" <| \() ->
Environment.decodePairs
( Environment.variableWithOptionalPrefix
"PREFIX_"
Environment.Variable
{ Environment.name = "TEST",
Environment.description = "test",
Environment.defaultValue = "default"
}
Environment.text
)
Dict.empty
|> Expect.equal (Ok "default")
]
]
4 changes: 2 additions & 2 deletions nri-http/src/Http.hs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ handlerWith :: HttpSettings -> Conduit.Acquire Handler
handlerWith settings = do
doAnything <- liftIO Platform.doAnythingHandler
manager <- TLS.newTlsManager
pure
<| Internal.Handler
pure <|
Internal.Handler
(_request settings doAnything manager)
(_withThirdParty settings manager)
(_withThirdPartyIO settings manager)
Expand Down
4 changes: 2 additions & 2 deletions nri-http/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ expectRequest run = do
let app req _respond = Exception.throwIO (FirstRequest req)
log <- Expect.succeeds Platform.logHandler
either <- Expect.fromIO <| Exception.try (withServerIO log app run)
Expect.succeeds
<| case either of
Expect.succeeds <|
case either of
Prelude.Left (FirstRequest req) -> Task.succeed req
Prelude.Right (Ok _) -> Task.fail "Expected a request, but none was received."
Prelude.Right (Err err) -> Task.fail (Debug.toString err)
Expand Down
4 changes: 2 additions & 2 deletions nri-kafka/src/Kafka.hs
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ sendHelperAsync producer doAnything onDeliveryCallback msg' = do
record'
( \deliveryReport -> do
log <- Platform.silentHandler
Task.perform log
<| case deliveryReport of
Task.perform log <|
case deliveryReport of
Producer.DeliverySuccess _producerRecord _offset -> onDeliveryCallback
_ -> Task.succeed ()
)
Expand Down
4 changes: 2 additions & 2 deletions nri-kafka/src/Kafka/Worker/Fetcher.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ pollingLoop'
-- See https://github.com/confluentinc/librdkafka/blob/c282ba2423b2694052393c8edb0399a5ef471b3f/CHANGELOG.md?plain=1#L90-L95
--
-- We have a small app to reproduce the bug. Check out scripts/pause-resume-bug/README.md
MVar.withMVar consumerLock
<| \_ -> Consumer.pollMessageBatch consumer pollingTimeout pollBatchSize
MVar.withMVar consumerLock <|
\_ -> Consumer.pollMessageBatch consumer pollingTimeout pollBatchSize
msgs <- Prelude.traverse handleKafkaError eitherMsgs
assignment <-
Consumer.assignment consumer
Expand Down
20 changes: 10 additions & 10 deletions nri-kafka/src/Kafka/Worker/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ rebalanceCallback skipOrNot messageFormat observability callback offsetSource co
callback
state
partitionKey
STM.atomically
<| TVar.modifyTVar' (rebalanceInfo state) (Dict.insert partitionKey (Assign, now))
STM.atomically <|
TVar.modifyTVar' (rebalanceInfo state) (Dict.insert partitionKey (Assign, now))
)
|> map (\_ -> ())
Consumer.RebalanceAssign _ -> Prelude.pure ()
Expand Down Expand Up @@ -604,12 +604,12 @@ pauseAndAnalyticsLoop maxBufferSize consumer consumerLock state pausedPartitions
-- See https://github.com/confluentinc/librdkafka/blob/c282ba2423b2694052393c8edb0399a5ef471b3f/CHANGELOG.md?plain=1#L90-L95
--
-- We have a small app to reproduce the bug. Check out scripts/pause-resume-bug/README.md
unless (Set.isEmpty newlyPaused && Set.isEmpty newlyResumed)
<| MVar.withMVar consumerLock
<| \_ -> do
_ <- Consumer.pausePartitions consumer (Set.toList newlyPaused)
_ <- Consumer.resumePartitions consumer (Set.toList newlyResumed)
Prelude.pure ()
unless (Set.isEmpty newlyPaused && Set.isEmpty newlyResumed) <|
MVar.withMVar consumerLock <|
\_ -> do
_ <- Consumer.pausePartitions consumer (Set.toList newlyPaused)
_ <- Consumer.resumePartitions consumer (Set.toList newlyResumed)
Prelude.pure ()
Control.Concurrent.threadDelay 1_000_000 {- 1 second -}
pauseAndAnalyticsLoop maxBufferSize consumer consumerLock state desiredPausedPartitions

Expand All @@ -621,8 +621,8 @@ pausedPartitionKeys (Settings.MaxMsgsPerPartitionBufferedLocally maxBufferSize)
|> Prelude.traverse
( \(key, partition) -> do
maybeLen <- Partition.length partition
Prelude.pure
<| case maybeLen of
Prelude.pure <|
case maybeLen of
Nothing -> Nothing
Just length ->
if length > maxBufferSize
Expand Down
20 changes: 10 additions & 10 deletions nri-kafka/src/Kafka/Worker/Partition.hs
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ spawnWorkerThread skipOrNot messageFormat commitOffsets observabilityHandler ana
-- partition as soon as this function returns, even if the processing thread
-- we start below still needs boot.
partition <-
map Partition
<| TVar.newTVarIO
<| case commitOffsets of
ToKafka -> Assigned Seq.empty
Elsewhere offset -> AwaitingSeekTo offset
ElsewhereButToKafkaAsWell offset -> AwaitingSeekTo offset
map Partition <|
TVar.newTVarIO <|
case commitOffsets of
ToKafka -> Assigned Seq.empty
Elsewhere offset -> AwaitingSeekTo offset
ElsewhereButToKafkaAsWell offset -> AwaitingSeekTo offset
onStartup partition
Exception.finally
(processMsgLoop skipOrNot messageFormat commitOffsets observabilityHandler State {analytics, stopping, partition} consumer callback)
Expand Down Expand Up @@ -441,8 +441,8 @@ peekRecord state =
StopThread
( do
next <-
STM.atomically
<| do
STM.atomically <|
do
let (Partition partition') = partition state
backlog' <- TVar.readTVar partition'
case backlog' of
Expand Down Expand Up @@ -529,8 +529,8 @@ append item (Partition partition) =
length :: Partition -> Prelude.IO (Maybe Int)
length (Partition partition) = do
backlog <- TVar.readTVarIO partition
Prelude.pure
<| case backlog of
Prelude.pure <|
case backlog of
AwaitingSeekTo _ -> Nothing
Stopping -> Nothing
Assigned queue ->
Expand Down
4 changes: 2 additions & 2 deletions nri-kafka/test/Helpers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ test description body =
( \task' ->
Platform.bracketWithError
( -- create handler
Platform.doAnything doAnything
<| case Environment.decodeDefaults Settings.decoder of
Platform.doAnything doAnything <|
case Environment.decodeDefaults Settings.decoder of
Ok settings ->
map
Ok
Expand Down
4 changes: 2 additions & 2 deletions nri-kafka/test/Spec/Kafka/Worker/Integration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ tests =
if retryCount < 1
then STM.throwSTM (Prelude.userError "retry please")
else
Prelude.pure
<| Worker.SeekToOffset ((Worker.offset partitionOffset) + 1)
Prelude.pure <|
Worker.SeekToOffset ((Worker.offset partitionOffset) + 1)
)
msgs' <- waitFor msgsTVar (\items -> Set.size items == 1)
-- Assert that the message was recorded on its first retry
Expand Down
Loading