-
Notifications
You must be signed in to change notification settings - Fork 87
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
Refactor behavior spec #14
Conversation
startHydraNode is deliberately not parameterized to illustrate the benefit of using io-sim instead of IO in this test suite.
589ccbd
to
d99cd36
Compare
Also, 'expectationFailure' got replaced by 'error' (for now). Maybe use 'MonadThrow' instead?
d99cd36
to
1dd2c99
Compare
1dd2c99
to
2df2eba
Compare
This also required more lifted variants of hspec-expectations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments mostly about the introduction of Test.Util
: I like it and would go farther and use it as a Test.Prelude
exposing standard stuff from HSpec
.
import Network.TypedProtocol.Channel (createConnectedChannels) | ||
import Network.TypedProtocol.Driver.Simple (runPeer) | ||
import Test.Hspec.Core.Spec | ||
import Test.Util (shouldBe, shouldRunInSim) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not using Test.Hspec
which is the more general public interface of Hspec?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we could reexport Test.Hspec
from Test.Util
in order to start building a "Test Prelude" unifying how we write and run tests in Hydra?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a relict from where I tried to shuffle things a bit.. I like the idea of a Test.Prelude
though!
import GHC.Stack (SrcLoc, callStack) | ||
import Test.HUnit.Lang (FailureReason (ExpectedButGot, Reason), HUnitFailure (HUnitFailure)) | ||
|
||
failure :: (HasCallStack, MonadThrow m) => String -> m a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we settling for tuple-style or arguments-style constraints? Seems like we are using both in the code base, could be something to put in our coding conventions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have to settle on one style, I'd cast a vote for the tuple-style 😬
(_, loc) : _ -> Just loc | ||
_ -> Nothing | ||
|
||
failAfter :: (HasCallStack, MonadTimer m, MonadThrow m) => DiffTime -> m () -> m () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like those more generic assertions.
import Hydra.Logging (nullTracer) | ||
import System.Timeout (timeout) | ||
import Test.Hspec (Spec, describe, it, shouldReturn) | ||
import Test.Hspec.Core.Spec (Spec, describe, it) | ||
import Test.Util (shouldReturn) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same remarks than for FireForgetSpec: We should reexport Test.Hspec
from Test.Util
and simplify imports for testing purpose
|
||
it "accepts a tx after the head was opened between two nodes" $ do | ||
it "is Ready when started" $ | ||
shouldRunInSim $ do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that all tests use shouldRunInSim
perhaps we could have a specialised it
combinator for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought about that quickly, but then put it off as being about the same overhead in typing/reading. I have no preference..what would you call that it
variation?
This is to avoid resource leakage. However there is still a "SloppyShutdown" reported by io-sim's runSimStrictShutdown for some cases. Furthermore, the HydraProcess handle was renamed to 'TestHydraNode' as I did not manage to get rid of it. Specifically it is required to 'waitForResponse'.
Run
BehaviorSpec
(andFireForgetSpec
) inIOSim
This is primarily to deal with longer contestationPeriods.
Next steps:
runSimStrictShutdown
and ensure proper thread clean-up inBehaviorSpec
-> most threads are cleaned up, but not allHydraProcess
(and useHydraNode
instead) -> could not get rid of it fully