swarm: calc kad depth outside loop in EachBin test

This commit is contained in:
Fabio Barone 2018-12-17 11:56:32 -05:00
parent c305a3eb83
commit 8de234a335

View file

@ -843,9 +843,10 @@ func TestEachBin(t *testing.T) {
} }
//run the k.EachBin function //run the k.EachBin function
k.EachBin(addr[:], pot.DefaultPof(k.MaxProxDisplay), 0, eachBinFunc) k.EachBin(addr[:], pot.DefaultPof(k.MaxProxDisplay), 0, eachBinFunc)
//calculate the kademlia depth
kdepth := k.NeighbourhoodDepth()
//now, check that all peers have the expected (fake) subscriptions //now, check that all peers have the expected (fake) subscriptions
//iterate the bin map //iterate the bin map
for bin, peers := range binMap { for bin, peers := range binMap {
//for every peer... //for every peer...
@ -853,7 +854,7 @@ func TestEachBin(t *testing.T) {
//...get its (fake) subscriptions //...get its (fake) subscriptions
fakeSubs := fakeSubscriptions[peer] fakeSubs := fakeSubscriptions[peer]
//if the peer's bin is below the kademlia depth... //if the peer's bin is below the kademlia depth...
if bin < k.NeighbourhoodDepth() { if bin < kdepth {
//(iterate all (fake) subscriptions) //(iterate all (fake) subscriptions)
for _, subbin := range fakeSubs { for _, subbin := range fakeSubs {
//...only the peer's bin should be "subscribed" //...only the peer's bin should be "subscribed"
@ -867,7 +868,7 @@ func TestEachBin(t *testing.T) {
for i, subbin := range fakeSubs { for i, subbin := range fakeSubs {
//...each bin from the peer's bin number up to k.MaxProxDisplay should be "subscribed" //...each bin from the peer's bin number up to k.MaxProxDisplay should be "subscribed"
// as we start from depth we can use the iteration index to check // as we start from depth we can use the iteration index to check
if subbin != i+k.NeighbourhoodDepth() { if subbin != i+kdepth {
t.Fatalf("Did not get expected subscription for bin > depth; bin of peer %s: %d, subscription: %d", peer, bin, subbin) t.Fatalf("Did not get expected subscription for bin > depth; bin of peer %s: %d, subscription: %d", peer, bin, subbin)
} }
//the last "subscription" should be k.MaxProxDisplay //the last "subscription" should be k.MaxProxDisplay