diff options
-rw-r--r-- | test/core/util/port_posix.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/test/core/util/port_posix.c b/test/core/util/port_posix.c index 55150a7ced..36f13e1b51 100644 --- a/test/core/util/port_posix.c +++ b/test/core/util/port_posix.c @@ -117,9 +117,10 @@ int grpc_pick_unused_port(void) { for (;;) { int port; - if (try == 0) { + try++; + if (try == 1) { port = getpid() % (65536 - 30000) + 30000; - } else if (try < NUM_RANDOM_PORTS_TO_PICK) { + } else if (try <= NUM_RANDOM_PORTS_TO_PICK) { port = rand() % (65536 - 30000) + 30000; } else { port = 0; |