Skip to content

WIP io-sim: flushTQueue does not maintain order #136

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

Closed
wants to merge 2 commits into from

Conversation

ch1bo
Copy link
Member

@ch1bo ch1bo commented Jan 30, 2024

Quick reproduction to confirm another bug in flushTQueue discovered while working on #133.

This currently fails:

cabal test io-sim --test-options '-p "/flushTQueue/&&/maintains FIFO order/"'
Build profile: -w ghc-9.4.8 -O1
In order, the following will be built (use -v for more details):
 - io-sim-1.3.1.1 (test:test) (first run)
Preprocessing test suite 'test' for io-sim-1.3.1.1..
Building test suite 'test' for io-sim-1.3.1.1..
Running 1 test suites...
Test suite test: RUNNING...
io-sim-tests
  IOSim
    MonadSTM
      flushTQueue
        maintains FIFO order: FAIL
          *** Failed! Falsified (after 5 tests and 3 shrinks):
          [0,1]
          [1,0] /= [0,1]
          Use --quickcheck-replay=54990 to reproduce.

1 out of 1 tests failed (0.00s)

Test suite test: FAIL
Test suite logged to:
/home/ch1bo/code/iog/io-sim/dist-newstyle/build/x86_64-linux/ghc-9.4.8/io-sim-1.3.1.1/t/test/test/io-sim-1.3.1.1-test.log
0 of 1 test suites (0 of 1 test cases) passed.
Error: cabal: Tests failed for test:test from io-sim-1.3.1.1.

Copy link
Collaborator

@coot coot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a minor comment.

@@ -1,6 +1,6 @@
cabal-version: 3.0
name: io-sim
version: 1.3.1.0
version: 1.3.1.1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you revert this, I figure out version changes when releasing to hackage.

@@ -95,7 +95,10 @@ tryPeekTQueueDefault (TQueue queue) = do
[] -> Nothing

flushTQueueDefault :: MonadSTM m => TQueueDefault m a -> STM m [a]
flushTQueueDefault (TQueue queue) = uncurry (++) <$> readTVar queue
flushTQueueDefault (TQueue queue) = do
xs <- uncurry (++) <$> readTVar queue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to reverse the tail, e.g.

Suggested change
xs <- uncurry (++) <$> readTVar queue
xs <- (\front tail -> front ++ reverse tail) <$> readTVar queue

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know.. I was not trying to fix it yet, but get the other PR merged first.

@ch1bo
Copy link
Member Author

ch1bo commented Jan 31, 2024

Moved into #135

@ch1bo ch1bo closed this Jan 31, 2024
@ch1bo ch1bo deleted the test-flushtqueue-order branch January 31, 2024 10:19
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