Browse Source

tx_proxy, tests: remove excess waiting in CheckTableBecome*()

Use TTestActorRuntimeBase::DispatchTimeout manipulation to achieve
proper (small) wait times.

The reason to this is that timeout value given to CheckTableBecome*()
propagates first to Tests:TClient::WaitForTablet*(), then propagates
to NActors::TTestActorsRuntimebase::GrabEdgeEvent().

Timeout parameter to GrabEdgeEvent*() is a timeout in a simulated time.
Timeout mechanics does not work if time does not get updated during a simulation.
And entire time simulation mechanics does not work if TTestActorRuntimeBase
is used with UseRealThreads setting set to true (which is the default).

And when timeout in a simulated time does not work, the only timeout
GrabEdgeEvent*() really obeys is DispatchTimeout which defaults to 60
seconds (or 120 seconds if code runs under some sanitizer).

Tests in ydb/core/tx/tx_proxy runs with UseRealThreads set to true,
so timeouts in CheckTableBecome*() methods do nothing, and whenever
tests wait for something that should never happen (and specify small
reasonable timeout value for that) they wait for 60 (or 120) seconds instead.

This change cuts run time of the affected tests from 7 minutes to 2.
ijon 2 years ago
parent
commit
2833f666f6
1 changed files with 15 additions and 6 deletions
  1. 15 6
      ydb/core/tx/tx_proxy/proxy_ut_helpers.cpp

+ 15 - 6
ydb/core/tx/tx_proxy/proxy_ut_helpers.cpp

@@ -394,18 +394,27 @@ void CheckTableIsOfline(TBaseTestEnv &env, ui64 tablet_id) {
 }
 
 void CheckTableBecomeAlive(TBaseTestEnv &env, ui64 tablet_id) {
+    auto prev = env.GetRuntime().SetDispatchTimeout(WaitTimeOut);
     UNIT_ASSERT(
                 env.GetClient().WaitForTabletAlive(&env.GetRuntime(), tablet_id, true, WaitTimeOut));
-
+    env.GetRuntime().SetDispatchTimeout(prev);
 }
 
 void CheckTableBecomeOfline(TBaseTestEnv &env, ui64 tablet_id) {
-    UNIT_ASSERT(
-                env.GetClient().WaitForTabletDown(&env.GetRuntime(), tablet_id, true, WaitTimeOut));
-    //ensure that tablet do not wake up
+    {
+        auto prev = env.GetRuntime().SetDispatchTimeout(WaitTimeOut);
+        UNIT_ASSERT(
+                    env.GetClient().WaitForTabletDown(&env.GetRuntime(), tablet_id, true, WaitTimeOut));
+        env.GetRuntime().SetDispatchTimeout(prev);
+    }
+    // check that tablet did not wake up
     TDuration negativeTimeout = TDuration::Seconds(1);
-    UNIT_ASSERT(
-                !env.GetClient().WaitForTabletAlive(&env.GetRuntime(), tablet_id, true, negativeTimeout));
+    {
+        auto prev = env.GetRuntime().SetDispatchTimeout(negativeTimeout);
+        UNIT_ASSERT(
+                    !env.GetClient().WaitForTabletAlive(&env.GetRuntime(), tablet_id, true, negativeTimeout));
+        env.GetRuntime().SetDispatchTimeout(prev);
+    }
 }
 
 void CheckTableRunOnProperTenantNode(TBaseTestEnv &env, const TString &tenant, ui64 tablet_id) {