From 6ed441403d3def9c7ccc89f75af1d1394ea28fa6 Mon Sep 17 00:00:00 2001 From: Trolli Schmittlauch Date: Mon, 11 May 2020 12:32:10 +0200 Subject: [PATCH] basic test for whether message splitting works --- Hash2Pub/src/Hash2Pub/ASN1Coding.hs | 2 +- Hash2Pub/test/FediChordSpec.hs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Hash2Pub/src/Hash2Pub/ASN1Coding.hs b/Hash2Pub/src/Hash2Pub/ASN1Coding.hs index 8446427..2c463b9 100644 --- a/Hash2Pub/src/Hash2Pub/ASN1Coding.hs +++ b/Hash2Pub/src/Hash2Pub/ASN1Coding.hs @@ -22,7 +22,7 @@ import Hash2Pub.DHTProtocol import Debug.Trace --- TODO: make this splitting function more intelligent, currently it creates many parts that are smaller than they could be +-- TODO: make this splitting function more intelligent, currently it creates many parts that are smaller than they could be, see #18 -- | Try splitting a payload into multiple parts to be able to reduce size of -- individual messages. -- Only some kinds of payloads can be split, and only to a limited number of parts. diff --git a/Hash2Pub/test/FediChordSpec.hs b/Hash2Pub/test/FediChordSpec.hs index 7bd5009..56dc473 100644 --- a/Hash2Pub/test/FediChordSpec.hs +++ b/Hash2Pub/test/FediChordSpec.hs @@ -228,8 +228,17 @@ spec = do encodeDecodeAndCheck $ responseWith Leave lResPayload encodeDecodeAndCheck $ responseWith Stabilise stabResPayload encodeDecodeAndCheck $ responseWith Ping pingResPayload - it "messages are encoded and decoded to ASN.1 DER properly" $ do + it "messages are encoded and decoded to ASN.1 DER properly" $ deserialiseMessage (head $ 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 + 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 + length (serialiseMessage 600 largeMessage) > 1 `shouldBe` True + length (serialiseMessage 6000 largeMessage) `shouldBe` 1 -- some example data