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
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
//iterate the bin map
for bin, peers := range binMap {
//for every peer...
@ -853,7 +854,7 @@ func TestEachBin(t *testing.T) {
//...get its (fake) subscriptions
fakeSubs := fakeSubscriptions[peer]
//if the peer's bin is below the kademlia depth...
if bin < k.NeighbourhoodDepth() {
if bin < kdepth {
//(iterate all (fake) subscriptions)
for _, subbin := range fakeSubs {
//...only the peer's bin should be "subscribed"
@ -867,7 +868,7 @@ func TestEachBin(t *testing.T) {
for i, subbin := range fakeSubs {
//...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
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)
}
//the last "subscription" should be k.MaxProxDisplay