add test for serialiseMessage part numbering
This commit is contained in:
parent
e32f0c9146
commit
cb769e088f
|
@ -5,7 +5,7 @@ import Control.Exception
|
||||||
import Data.ASN1.Parse (runParseASN1)
|
import Data.ASN1.Parse (runParseASN1)
|
||||||
import qualified Data.ByteString as BS
|
import qualified Data.ByteString as BS
|
||||||
import qualified Data.Map.Strict as Map
|
import qualified Data.Map.Strict as Map
|
||||||
import Data.Maybe (fromJust)
|
import Data.Maybe (fromJust, isJust)
|
||||||
import qualified Data.Set as Set
|
import qualified Data.Set as Set
|
||||||
import Data.Time.Clock.POSIX
|
import Data.Time.Clock.POSIX
|
||||||
import Network.Socket
|
import Network.Socket
|
||||||
|
@ -212,6 +212,12 @@ spec = do
|
||||||
responseWith a pa = responseTemplate {action = a, payload = Just pa}
|
responseWith a pa = responseTemplate {action = a, payload = Just pa}
|
||||||
|
|
||||||
encodeDecodeAndCheck msg = runParseASN1 parseMessage (encodeMessage msg) `shouldBe` pure msg
|
encodeDecodeAndCheck msg = runParseASN1 parseMessage (encodeMessage msg) `shouldBe` pure msg
|
||||||
|
largeMessage = responseWith Join $ JoinResponsePayload {
|
||||||
|
joinSuccessors = fromInteger <$> [-20..150]
|
||||||
|
, joinPredecessors = fromInteger <$> [5..11]
|
||||||
|
, joinCache = [ RemoteCacheEntry (exampleNodeState {nid = node}) 290001 | node <- [50602,506011..60000]]
|
||||||
|
}
|
||||||
|
|
||||||
it "messages are encoded and decoded correctly from and to ASN1" $ do
|
it "messages are encoded and decoded correctly from and to ASN1" $ do
|
||||||
encodeDecodeAndCheck $ requestWith QueryID qidReqPayload
|
encodeDecodeAndCheck $ requestWith QueryID qidReqPayload
|
||||||
encodeDecodeAndCheck $ requestWith Join jReqPayload
|
encodeDecodeAndCheck $ requestWith Join jReqPayload
|
||||||
|
@ -227,14 +233,14 @@ spec = do
|
||||||
it "messages are encoded and decoded to ASN.1 DER properly" $
|
it "messages are encoded and decoded to ASN.1 DER properly" $
|
||||||
deserialiseMessage (fromJust $ Map.lookup 1 (serialiseMessage 652 $ responseWith Ping pingResPayload)) `shouldBe` Right (responseWith Ping pingResPayload)
|
deserialiseMessage (fromJust $ Map.lookup 1 (serialiseMessage 652 $ responseWith Ping pingResPayload)) `shouldBe` Right (responseWith Ping pingResPayload)
|
||||||
it "messages too large for a single packet can (often) be split into multiple parts" $ do
|
it "messages too large for a single packet can (often) be split into multiple parts" $ do
|
||||||
let largeMessage = responseWith Join $ JoinResponsePayload {
|
|
||||||
joinSuccessors = fromInteger <$> [-20..150]
|
|
||||||
, joinPredecessors = fromInteger <$> [5..11]
|
|
||||||
, joinCache = [ RemoteCacheEntry (exampleNodeState {nid = node}) 290001 | node <- [50602,506011..60000]]
|
|
||||||
}
|
|
||||||
-- TODO: once splitting works more efficient, test for exact number or payload, see #18
|
-- TODO: once splitting works more efficient, test for exact number or payload, see #18
|
||||||
length (serialiseMessage 600 largeMessage) > 1 `shouldBe` True
|
length (serialiseMessage 600 largeMessage) > 1 `shouldBe` True
|
||||||
length (serialiseMessage 6000 largeMessage) `shouldBe` 1
|
length (serialiseMessage 6000 largeMessage) `shouldBe` 1
|
||||||
|
it "message part numbering starts at the submitted part number" $ do
|
||||||
|
isJust (Map.lookup 1 (serialiseMessage 600 largeMessage)) `shouldBe` True
|
||||||
|
let startAt5 = serialiseMessage 600 (largeMessage {part = 5})
|
||||||
|
Map.lookup 1 startAt5 `shouldBe` Nothing
|
||||||
|
part <$> (deserialiseMessage . fromJust) (Map.lookup 5 startAt5) `shouldBe` Right 5
|
||||||
|
|
||||||
|
|
||||||
-- some example data
|
-- some example data
|
||||||
|
|
Loading…
Reference in a new issue