diff --git a/transport/routing_test.go b/transport/routing_test.go new file mode 100644 index 00000000..9485577b --- /dev/null +++ b/transport/routing_test.go @@ -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) + } + } + } + } +}