Merge pull request #15335 from adelez/foundry_integration

Pick a random starting port
pull/15339/head
adelez 7 years ago committed by GitHub
commit 1f1b2ad4b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      test/core/util/port_isolated_runtime_environment.cc

@ -19,19 +19,28 @@
/* When running tests on remote machines, the framework takes a round-robin pick /* When running tests on remote machines, the framework takes a round-robin pick
* of a port within certain range. There is no need to recycle ports. * of a port within certain range. There is no need to recycle ports.
*/ */
#include <grpc/support/time.h>
#include <stdlib.h>
#include "src/core/lib/iomgr/port.h" #include "src/core/lib/iomgr/port.h"
#include "test/core/util/test_config.h" #include "test/core/util/test_config.h"
#if defined(GRPC_PORT_ISOLATED_RUNTIME) #if defined(GRPC_PORT_ISOLATED_RUNTIME)
#include "test/core/util/port.h" #include "test/core/util/port.h"
#define LOWER_PORT 49152 #define MIN_PORT 49152
static int s_allocated_port = LOWER_PORT; #define MAX_PORT 65536
int get_random_starting_port() {
srand(gpr_now(GPR_CLOCK_REALTIME).tv_nsec);
return rand() % (MAX_PORT - MIN_PORT + 1) + MIN_PORT;
}
static int s_allocated_port = get_random_starting_port();
int grpc_pick_unused_port_or_die(void) { int grpc_pick_unused_port_or_die(void) {
int allocated_port = s_allocated_port++; int allocated_port = s_allocated_port++;
if (s_allocated_port == 65536) { if (s_allocated_port == MAX_PORT) {
s_allocated_port = LOWER_PORT; s_allocated_port = MIN_PORT;
} }
return allocated_port; return allocated_port;

Loading…
Cancel
Save