From b3e3317ae8f4f760b8ecf73ccff11261192a795d Mon Sep 17 00:00:00 2001
From: ctiller <ctiller@google.com>
Date: Mon, 5 Jan 2015 14:40:53 -0800
Subject: [PATCH] Seed random numbers in each process based on pid.

This causes get_unused_port_or_die to try different port numbers in each
concurrently running tests, and consequently enables some parallelism of test
processes.
	Change on 2015/01/05 by ctiller <ctiller@google.com>
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=83289374
---
 test/core/echo/echo_test.c          | 4 ++++
 test/core/fling/fling_stream_test.c | 4 ++++
 test/core/fling/fling_test.c        | 4 ++++
 test/core/util/test_config.c        | 9 ++++++++-
 4 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/test/core/echo/echo_test.c b/test/core/echo/echo_test.c
index 748e8bc0ef..16d381fb65 100644
--- a/test/core/echo/echo_test.c
+++ b/test/core/echo/echo_test.c
@@ -37,6 +37,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <signal.h>
+#include <stdlib.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 
@@ -80,6 +81,9 @@ int main(int argc, char **argv) {
   pid_t svr;
   int ret;
   int do_ipv6 = 1;
+  /* seed rng with pid, so we don't end up with the same random numbers as a
+     concurrently running test binary */
+  srand(getpid());
   if (!grpc_ipv6_loopback_available()) {
     gpr_log(GPR_INFO, "Can't bind to ::1.  Skipping IPv6 tests.");
     do_ipv6 = 0;
diff --git a/test/core/fling/fling_stream_test.c b/test/core/fling/fling_stream_test.c
index a24240ef1d..f6fe69824b 100644
--- a/test/core/fling/fling_stream_test.c
+++ b/test/core/fling/fling_stream_test.c
@@ -37,6 +37,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <signal.h>
+#include <stdlib.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 
@@ -53,6 +54,9 @@ int main(int argc, char **argv) {
   char *args[10];
   int status;
   pid_t svr, cli;
+  /* seed rng with pid, so we don't end up with the same random numbers as a
+     concurrently running test binary */
+  srand(getpid());
   /* figure out where we are */
   if (lslash) {
     memcpy(root, me, lslash - me);
diff --git a/test/core/fling/fling_test.c b/test/core/fling/fling_test.c
index c6b369518c..4607aa5f98 100644
--- a/test/core/fling/fling_test.c
+++ b/test/core/fling/fling_test.c
@@ -37,6 +37,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <signal.h>
+#include <stdlib.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 
@@ -53,6 +54,9 @@ int main(int argc, char **argv) {
   char *args[10];
   int status;
   pid_t svr, cli;
+  /* seed rng with pid, so we don't end up with the same random numbers as a
+     concurrently running test binary */
+  srand(getpid());
   /* figure out where we are */
   if (lslash) {
     memcpy(root, me, lslash - me);
diff --git a/test/core/util/test_config.c b/test/core/util/test_config.c
index 993014aa14..fc5de9bbef 100644
--- a/test/core/util/test_config.c
+++ b/test/core/util/test_config.c
@@ -33,4 +33,11 @@
 
 #include "test/core/util/test_config.h"
 
-void grpc_test_init(int argc, char **argv) {}
+#include <stdlib.h>
+#include <unistd.h>
+
+void grpc_test_init(int argc, char **argv) {
+  /* seed rng with pid, so we don't end up with the same random numbers as a
+     concurrently running test binary */
+  srand(getpid());
+}
-- 
GitLab