Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Avoid unnecessary use of run #358

Merged
merged 1 commit into from
Mar 3, 2020
Merged

Avoid unnecessary use of run #358

merged 1 commit into from
Mar 3, 2020

Conversation

edsko
Copy link
Contributor

@edsko edsko commented Jan 2, 2020

The top-level of a QSM test typically looks something like this:

forAllCommands ... $ \cmds -> QC.monadicIO $ do
  (hist, prop) <- .... runCommands ...
  prettyCommands ...

The problem is that runCommands lives in PropertyM. This makes it impossible to do any kind of bracketing. Fortunately, it turns out that this use of PropertyM is actually not needed at all. In this commit, I remove it without having to change much at all, except having to insert a few extra runs in the test. In particular, the above will now turn into

forAllCommands ... $ \cmds -> QC.monadicIO $ do
  (hist, prop) <- .... run ( runCommands ... ) ...
  prettyCommands ...

which, crucially, would allow us to do something like

forAllCommands ... $ \cmds -> QC.monadicIO $ do
  (hist, prop) <- .... run (bracket ... $ \r -> runCommands .. r .. ) ...
  prettyCommands ...

NOTE: I'm getting a test failure, but that exists on master already:

  Rqlite
    parallel:                                                      FAIL (0.30s)
      *** Failed! Falsified (after 1 test and 4 shrinks):
      ParallelCommands
        { prefix =
            Commands
              { unCommands =
                  [ Command
                      Spawn
                      0
                      1
                      s
                      1
                      s
                      Nothing
                      Resp
                      (Right (Spawned (Reference (Symbolic (Var 0)))))
                      [ Var 0 ]
                  ]
              }
        , suffixes = []
        }
      Use --quickcheck-replay=727617 to reproduce.
  ErrorEncountered

I don't think that's related to this PR at all though.

@stevana
Copy link
Collaborator

stevana commented Jan 3, 2020

Would it make sense to name the run function that doesn't use PropertyM as runCommands' :: m ... and then define the old run function runCommands = run . runCommands' :: PropertyM m..., and thus not break backwards compatibility?

NOTE: I'm getting a test failure, but that exists on master already

Yeah, there's a ticket for this already #356

@edsko
Copy link
Contributor Author

edsko commented Jan 3, 2020

Would it make sense to name the run function that doesn't use PropertyM as runCommands' :: m ... and then define the old run function runCommands = run . runCommands' :: PropertyM m..., and thus not break backwards compatibility?

Yes, I suppose that would be sensible, if you are worried about breaking compatibility.

The top-level of a QSM test typically looks something like this:

```haskell
forAllCommands ... $ \cmds -> QC.monadicIO $ do
  (hist, prop) <- .... runCommands ...
  prettyCommands ...
```

The problem is that `runCommands` lives in `PropertyM`. This makes it
impossible to do any kind of bracketing. Fortunately, it turns out that this
use of `PropertyM` is actually not needed at all. In this commit, I add
`runCommands'`, which lives in `m`. To avoid breaking backwards compatibility,
`runCommands` still lives in `PropertyM` and is a combination of `run` and
`runCommands'`.

This will allow us to do something like:

```haskell
forAllCommands ... $ \cmds -> QC.monadicIO $ do
  (hist, prop) <- .... run (bracket ... $ \r -> runCommands' .. r .. ) ...
  prettyCommands ...
```

Co-authored-by: Thomas Winant <[email protected]>
Signed-off-by: Edsko de Vries <[email protected]>
@mrBliss
Copy link
Contributor

mrBliss commented Mar 3, 2020

Would it make sense to name the run function that doesn't use PropertyM as runCommands' :: m ... and then define the old run function runCommands = run . runCommands' :: PropertyM m..., and thus not break backwards compatibility?

I have updated the PR to follow this approach.

@stevana
Copy link
Collaborator

stevana commented Mar 3, 2020

Sweet, lets get this merged!

@mrBliss
Copy link
Contributor

mrBliss commented Mar 3, 2020

Sweet, lets get this merged!

Yeah, let's merge this 👍

@stevana stevana merged commit 19c5080 into advancedtelematic:master Mar 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants