mirror of https://github.com/voidlizard/hbs2
wip
This commit is contained in:
parent
952bb05d6e
commit
69cd2622f2
|
@ -116,6 +116,7 @@ test-suite test
|
||||||
|
|
||||||
other-modules: TestFakeMessaging
|
other-modules: TestFakeMessaging
|
||||||
, TestActors
|
, TestActors
|
||||||
|
, TestBlockInfoActor
|
||||||
|
|
||||||
-- other-extensions:
|
-- other-extensions:
|
||||||
|
|
||||||
|
@ -131,6 +132,7 @@ test-suite test
|
||||||
, microlens-platform
|
, microlens-platform
|
||||||
, mtl
|
, mtl
|
||||||
, prettyprinter
|
, prettyprinter
|
||||||
|
, QuickCheck
|
||||||
, random
|
, random
|
||||||
, safe
|
, safe
|
||||||
, serialise
|
, serialise
|
||||||
|
|
|
@ -4,8 +4,11 @@ import HBS2.Prelude
|
||||||
import HBS2.Hash
|
import HBS2.Hash
|
||||||
import HBS2.Net.Proto
|
import HBS2.Net.Proto
|
||||||
import HBS2.Clock
|
import HBS2.Clock
|
||||||
|
import HBS2.Actors
|
||||||
|
|
||||||
import Data.Function
|
import Data.Function
|
||||||
|
import Data.Kind
|
||||||
|
import Prettyprinter
|
||||||
|
|
||||||
-- needs: logger
|
-- needs: logger
|
||||||
-- needs: reader and shit
|
-- needs: reader and shit
|
||||||
|
@ -13,9 +16,9 @@ import Data.Function
|
||||||
-- needs: cookie manager
|
-- needs: cookie manager
|
||||||
-- needs: peer manager
|
-- needs: peer manager
|
||||||
|
|
||||||
data BlockInfoActor =
|
data BlockInfoActor (m :: Type -> Type) =
|
||||||
BlockInfoActor
|
BlockInfoActor
|
||||||
{
|
{ tasks :: Pipeline m ()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,27 +28,31 @@ data BlockInfoActor =
|
||||||
-- TODO: get block info per peer
|
-- TODO: get block info per peer
|
||||||
|
|
||||||
|
|
||||||
createBlockInfoActor :: MonadIO m => m BlockInfoActor
|
createBlockInfoActor :: MonadIO m => m (BlockInfoActor m )
|
||||||
createBlockInfoActor = do
|
createBlockInfoActor = do
|
||||||
pure $ BlockInfoActor
|
pip <- newPipeline 200 -- FIXME: to settings!
|
||||||
|
pure $ BlockInfoActor pip
|
||||||
|
|
||||||
runBlockInfoActor :: MonadIO m => BlockInfoActor -> m ()
|
runBlockInfoActor :: MonadIO m => BlockInfoActor m -> m ()
|
||||||
runBlockInfoActor _ =
|
runBlockInfoActor b = runPipeline (tasks b)
|
||||||
fix \next -> do
|
|
||||||
pause (1 :: Timeout 'Seconds)
|
|
||||||
next
|
|
||||||
|
|
||||||
requestBlockInfo :: MonadIO m
|
stopBlockInfoActor :: MonadIO m => BlockInfoActor m -> m ()
|
||||||
=> BlockInfoActor
|
stopBlockInfoActor b = stopPipeline (tasks b)
|
||||||
|
|
||||||
|
requestBlockInfo :: forall peer h m . ( MonadIO m
|
||||||
|
, Pretty (Hash h)
|
||||||
|
)
|
||||||
|
=> BlockInfoActor m
|
||||||
-> Maybe (Peer peer)
|
-> Maybe (Peer peer)
|
||||||
-> Hash h
|
-> Hash h
|
||||||
-> m ()
|
-> m ()
|
||||||
|
|
||||||
requestBlockInfo b h = do
|
requestBlockInfo b _ h = do
|
||||||
undefined
|
addJob (tasks b) do
|
||||||
|
liftIO $ print ( "request-info" <+> pretty h)
|
||||||
|
|
||||||
getBlockInfo :: MonadIO m
|
getBlockInfo :: MonadIO m
|
||||||
=> BlockInfoActor
|
=> BlockInfoActor m
|
||||||
-> Maybe (Peer peer)
|
-> Maybe (Peer peer)
|
||||||
-> m (Maybe BlockInfo)
|
-> m (Maybe BlockInfo)
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ module Main where
|
||||||
|
|
||||||
import TestFakeMessaging
|
import TestFakeMessaging
|
||||||
import TestActors
|
import TestActors
|
||||||
|
import TestBlockInfoActor
|
||||||
|
|
||||||
import Test.Tasty
|
import Test.Tasty
|
||||||
import Test.Tasty.HUnit
|
import Test.Tasty.HUnit
|
||||||
|
@ -13,6 +14,7 @@ main =
|
||||||
[
|
[
|
||||||
testCase "testFakeMessaging1" testFakeMessaging1
|
testCase "testFakeMessaging1" testFakeMessaging1
|
||||||
, testCase "testActorsBasic" testActorsBasic
|
, testCase "testActorsBasic" testActorsBasic
|
||||||
|
, testCase "testBlockInfoActor" testBlockInfoActor
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
module TestBlockInfoActor where
|
||||||
|
|
||||||
|
import HBS2.Hash
|
||||||
|
import HBS2.Clock
|
||||||
|
import HBS2.Net.Proto.Actors.BlockInfo
|
||||||
|
|
||||||
|
import Test.Tasty.HUnit
|
||||||
|
|
||||||
|
import Test.QuickCheck
|
||||||
|
import Data.Word
|
||||||
|
import Data.ByteString (ByteString)
|
||||||
|
import Data.ByteString qualified as B
|
||||||
|
import Control.Concurrent.Async
|
||||||
|
|
||||||
|
testBlockInfoActor :: IO ()
|
||||||
|
testBlockInfoActor = do
|
||||||
|
|
||||||
|
a <- createBlockInfoActor
|
||||||
|
actor <- async $ runBlockInfoActor a
|
||||||
|
|
||||||
|
let obj = shrink [0x00 .. 0xFF] :: [[Word8]]
|
||||||
|
|
||||||
|
forConcurrently_ obj $ \x -> do
|
||||||
|
requestBlockInfo a Nothing (hashObject (B.pack x) :: Hash HbSync)
|
||||||
|
|
||||||
|
pause ( 1 :: Timeout 'Seconds)
|
||||||
|
|
||||||
|
stopBlockInfoActor a
|
||||||
|
|
||||||
|
waitAnyCatchCancel [actor]
|
||||||
|
|
||||||
|
assertBool "testBlockInfoActor" True
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue