Skip to content
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

Merged
merged 9 commits into from
Jun 10, 2021
Merged

Refactor behavior spec #14

merged 9 commits into from
Jun 10, 2021

Conversation

ch1bo
Copy link
Member

@ch1bo ch1bo commented Jun 8, 2021

Run BehaviorSpec (and FireForgetSpec) in IOSim

This is primarily to deal with longer contestationPeriods.

Next steps:

  • Use runSimStrictShutdown and ensure proper thread clean-up in BehaviorSpec -> most threads are cleaned up, but not all
  • Get rid of HydraProcess (and use HydraNode instead) -> could not get rid of it fully

ch1bo added 3 commits June 8, 2021 16:33
startHydraNode is deliberately not parameterized to illustrate the
benefit of using io-sim instead of IO in this test suite.
@ch1bo ch1bo force-pushed the refactor-behavior-spec branch from 589ccbd to d99cd36 Compare June 8, 2021 14:33
Also, 'expectationFailure' got replaced by 'error' (for now). Maybe use
'MonadThrow' instead?
@ch1bo ch1bo force-pushed the refactor-behavior-spec branch from d99cd36 to 1dd2c99 Compare June 8, 2021 14:48
@ch1bo ch1bo force-pushed the refactor-behavior-spec branch from 1dd2c99 to 2df2eba Compare June 8, 2021 15:28
@ch1bo ch1bo requested review from a user and KtorZ June 9, 2021 15:23
Copy link

@ghost ghost left a 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)
Copy link

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?

Copy link

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?

Copy link
Member Author

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
Copy link

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.

Copy link
Collaborator

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 ()
Copy link

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)
Copy link

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
Copy link

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?

Copy link
Member Author

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'.
@ch1bo ch1bo merged commit c1852eb into master Jun 10, 2021
@ch1bo ch1bo deleted the refactor-behavior-spec branch June 10, 2021 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants