Skip to content

Commit

Permalink
transport: routing, added TestShardPortIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
Kulezi committed Sep 8, 2022
1 parent 8f0bca8 commit 88fc8ef
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions transport/routing_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package transport

import "testing"

func TestShardPortIterator(t *testing.T) {
t.Parallel()
for shards := 1; shards < 128; shards++ {
for shard := 0; shard < shards; shard++ {
si := ShardInfo{
Shard: uint16(shard),
NrShards: uint16(shards),
}

it := ShardPortIterator(si)
finishPort := it()
for port := it(); port != finishPort; port = it() {
if port < minPort || port > maxPort {
t.Fatalf("port %d is not in range [%d, %d]", port, minPort, maxPort)
}

if int(port)%shards != shard {
t.Fatalf("port %d doesn't correspond to shard %d", port, shard)
}
}
}
}
}

0 comments on commit 88fc8ef

Please sign in to comment.