From 88fc8ef65496a8d2ed514fdf5501016663c08635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Putra?= Date: Wed, 7 Sep 2022 15:33:28 +0200 Subject: [PATCH] transport: routing, added TestShardPortIterator --- transport/routing_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 transport/routing_test.go 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) + } + } + } + } +}