parent
e8091b0a29
commit
bbe7078369
|
@ -55,14 +55,13 @@ spec = do
|
||||||
it "can be initialised" $
|
it "can be initialised" $
|
||||||
print exampleNodeState
|
print exampleNodeState
|
||||||
it "can be initialised partly and then modified later" $ do
|
it "can be initialised partly and then modified later" $ do
|
||||||
let ns = NodeState {
|
let ns = RemoteNodeState {
|
||||||
nid = undefined
|
nid = undefined
|
||||||
, domain = exampleNodeDomain
|
, domain = exampleNodeDomain
|
||||||
, ipAddr = exampleIp
|
, ipAddr = exampleIp
|
||||||
, dhtPort = 2342
|
, dhtPort = 2342
|
||||||
, apPort = Nothing
|
, servicePort = 513
|
||||||
, vServerID = undefined
|
, vServerID = undefined
|
||||||
, internals = Nothing
|
|
||||||
}
|
}
|
||||||
nsReady = ns {
|
nsReady = ns {
|
||||||
nid = genNodeID (ipAddr ns) (domain ns) 3
|
nid = genNodeID (ipAddr ns) (domain ns) 3
|
||||||
|
@ -121,9 +120,7 @@ spec = do
|
||||||
let
|
let
|
||||||
emptyCache = initCache
|
emptyCache = initCache
|
||||||
nid1 = toNodeID 2^(23::Integer)+1
|
nid1 = toNodeID 2^(23::Integer)+1
|
||||||
node1 = do
|
node1 = setPredecessors [nid4] . setNid nid1 <$> exampleLocalNode
|
||||||
eln <- exampleLocalNode -- is at 2^23.00000017198264 = 8388609
|
|
||||||
pure $ putPredecessors [nid4] $ eln {nid = nid1}
|
|
||||||
nid2 = toNodeID 2^(230::Integer)+12
|
nid2 = toNodeID 2^(230::Integer)+12
|
||||||
node2 = exampleNodeState { nid = nid2}
|
node2 = exampleNodeState { nid = nid2}
|
||||||
nid3 = toNodeID 2^(25::Integer)+10
|
nid3 = toNodeID 2^(25::Integer)+10
|
||||||
|
@ -131,7 +128,7 @@ spec = do
|
||||||
nid4 = toNodeID 2^(9::Integer)+100
|
nid4 = toNodeID 2^(9::Integer)+100
|
||||||
node4 = exampleNodeState { nid = nid4}
|
node4 = exampleNodeState { nid = nid4}
|
||||||
cacheWith2Entries :: IO NodeCache
|
cacheWith2Entries :: IO NodeCache
|
||||||
cacheWith2Entries = addCacheEntryPure 10 <$> (RemoteCacheEntry <$> node1 <*> pure 10) <*> pure (addCacheEntryPure 10 (RemoteCacheEntry node2 10) emptyCache)
|
cacheWith2Entries = addCacheEntryPure 10 <$> (RemoteCacheEntry <$> (toRemoteNodeState <$> node1) <*> pure 10) <*> pure (addCacheEntryPure 10 (RemoteCacheEntry node2 10) emptyCache)
|
||||||
cacheWith4Entries = addCacheEntryPure 10 (RemoteCacheEntry node3 10) <$> (addCacheEntryPure 10 (RemoteCacheEntry node4 10) <$> cacheWith2Entries)
|
cacheWith4Entries = addCacheEntryPure 10 (RemoteCacheEntry node3 10) <$> (addCacheEntryPure 10 (RemoteCacheEntry node4 10) <$> cacheWith2Entries)
|
||||||
it "works on an empty cache" $ do
|
it "works on an empty cache" $ do
|
||||||
queryLocalCache <$> exampleLocalNode <*> pure emptyCache <*> pure 3 <*> pure (toNodeID 2^(9::Integer)+5) `shouldReturn` FORWARD Set.empty
|
queryLocalCache <$> exampleLocalNode <*> pure emptyCache <*> pure 3 <*> pure (toNodeID 2^(9::Integer)+5) `shouldReturn` FORWARD Set.empty
|
||||||
|
@ -146,9 +143,9 @@ spec = do
|
||||||
Set.map (nid . remoteNode) nodeset2 `shouldBe` Set.fromList [nid4]
|
Set.map (nid . remoteNode) nodeset2 `shouldBe` Set.fromList [nid4]
|
||||||
it "recognises the node's own responsibility" $ do
|
it "recognises the node's own responsibility" $ do
|
||||||
FOUND selfQueryRes <- queryLocalCache <$> node1 <*> cacheWith4Entries <*> pure 3 <*> pure nid1
|
FOUND selfQueryRes <- queryLocalCache <$> node1 <*> cacheWith4Entries <*> pure 3 <*> pure nid1
|
||||||
nid <$> node1 `shouldReturn` nid selfQueryRes
|
getNid <$> node1 `shouldReturn` getNid selfQueryRes
|
||||||
FOUND responsibilityResult <- queryLocalCache <$> node1 <*> cacheWith4Entries <*> pure 3 <*> pure (toNodeID 2^(22::Integer))
|
FOUND responsibilityResult <- queryLocalCache <$> node1 <*> cacheWith4Entries <*> pure 3 <*> pure (toNodeID 2^(22::Integer))
|
||||||
nid <$> node1 `shouldReturn` nid responsibilityResult
|
getNid <$> node1 `shouldReturn` getNid responsibilityResult
|
||||||
it "does not fail on nodes without neighbours (initial state)" $ do
|
it "does not fail on nodes without neighbours (initial state)" $ do
|
||||||
(FORWARD nodeset) <- queryLocalCache <$> exampleLocalNode <*> cacheWith4Entries <*> pure 3 <*> pure (toNodeID 11)
|
(FORWARD nodeset) <- queryLocalCache <$> exampleLocalNode <*> cacheWith4Entries <*> pure 3 <*> pure (toNodeID 11)
|
||||||
Set.map (nid . remoteNode ) nodeset `shouldBe` Set.fromList [nid4, nid2, nid3]
|
Set.map (nid . remoteNode ) nodeset `shouldBe` Set.fromList [nid4, nid2, nid3]
|
||||||
|
@ -243,18 +240,17 @@ spec = do
|
||||||
|
|
||||||
-- some example data
|
-- some example data
|
||||||
|
|
||||||
exampleNodeState :: NodeState
|
exampleNodeState :: RemoteNodeState
|
||||||
exampleNodeState = NodeState {
|
exampleNodeState = RemoteNodeState {
|
||||||
nid = toNodeID 12
|
nid = toNodeID 12
|
||||||
, domain = exampleNodeDomain
|
, domain = exampleNodeDomain
|
||||||
, ipAddr = exampleIp
|
, ipAddr = exampleIp
|
||||||
, dhtPort = 2342
|
, dhtPort = 2342
|
||||||
, apPort = Nothing
|
, servicePort = 513
|
||||||
, vServerID = 0
|
, vServerID = 0
|
||||||
, internals = Nothing
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exampleLocalNode :: IO NodeState
|
exampleLocalNode :: IO LocalNodeState
|
||||||
exampleLocalNode = nodeStateInit $ FediChordConf {
|
exampleLocalNode = nodeStateInit $ FediChordConf {
|
||||||
confDomain = "example.social"
|
confDomain = "example.social"
|
||||||
, confIP = exampleIp
|
, confIP = exampleIp
|
||||||
|
|
Loading…
Reference in a new issue