From ea9e479981b734a14e9b6e9fab143bb095fd0d68 Mon Sep 17 00:00:00 2001 From: hai007 Date: Mon, 28 Aug 2023 08:55:31 -0700 Subject: [PATCH 1/2] Add RECONNECT as a new EstablishedConnection's type. PiperOrigin-RevId: 560724376 --- proto/connections_enums.proto | 1 + 1 file changed, 1 insertion(+) diff --git a/proto/connections_enums.proto b/proto/connections_enums.proto index c5d25ae5..072b4625 100644 --- a/proto/connections_enums.proto +++ b/proto/connections_enums.proto @@ -157,6 +157,7 @@ enum ConnectionAttemptType { UNKNOWN_CONNECTION_ATTEMPT_TYPE = 0; INITIAL = 1; UPGRADE = 2; + RECONNECT = 3; } // The reason that an EstablishedConnection was disconnected. From 263b1b4e853d588dc468c605a56d36434a97ad44 Mon Sep 17 00:00:00 2001 From: Janusz Sobczak Date: Tue, 29 Aug 2023 11:54:53 -0700 Subject: [PATCH 2/2] Fix thread safety issue The test could fail if threads needed a bit more time to spin up. Test only change. PiperOrigin-RevId: 561097187 --- internal/platform/multi_thread_executor_test.cc | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/internal/platform/multi_thread_executor_test.cc b/internal/platform/multi_thread_executor_test.cc index 0085e05a..7166aa6a 100644 --- a/internal/platform/multi_thread_executor_test.cc +++ b/internal/platform/multi_thread_executor_test.cc @@ -28,7 +28,7 @@ namespace { const int kMaxThreads = 5; } -TEST(MultiThreadExecutorTest, ConsructorDestructorWorks) { +TEST(MultiThreadExecutorTest, ConstructorDestructorWorks) { MultiThreadExecutor executor(kMaxThreads); } @@ -58,7 +58,7 @@ TEST(MultiThreadExecutorTest, JobsExecuteInParallel) { int count = 0; for (int i = 0; i < kMaxThreads; ++i) { - executor.Execute([&count, &mutex, &test_cond, &thread_cond]() { + executor.Execute([&]() { absl::MutexLock lock(&mutex); count++; test_cond.Signal(); @@ -69,12 +69,9 @@ TEST(MultiThreadExecutorTest, JobsExecuteInParallel) { } { - absl::Duration duration = absl::Milliseconds(kMaxThreads * 100); absl::MutexLock lock(&mutex); while (count < kMaxThreads) { - absl::Time start = absl::Now(); - if (test_cond.WaitWithTimeout(&mutex, duration)) break; - duration -= absl::Now() - start; + if (test_cond.WaitWithTimeout(&mutex, absl::Seconds(30))) break; } } @@ -82,12 +79,9 @@ TEST(MultiThreadExecutorTest, JobsExecuteInParallel) { thread_cond.SignalAll(); { - absl::Duration duration = absl::Milliseconds(kMaxThreads * 100); absl::MutexLock lock(&mutex); while (count > 0) { - absl::Time start = absl::Now(); - if (test_cond.WaitWithTimeout(&mutex, duration)) break; - duration -= absl::Now() - start; + if (test_cond.WaitWithTimeout(&mutex, absl::Seconds(30))) break; } } EXPECT_EQ(count, 0);