You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by is...@apache.org on 2022/09/09 20:00:49 UTC

[ignite-3] 08/17: IGNITE-17424 Dry-run prior to all tests

This is an automated email from the ASF dual-hosted git repository.

isapego pushed a commit to branch ignite-17424
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit 713b1988cd38f62739f3d7a7722048f9ae0889bc
Author: Igor Sapego <is...@apache.org>
AuthorDate: Tue Aug 30 13:14:15 2022 +0400

    IGNITE-17424 Dry-run prior to all tests
---
 modules/platforms/cpp/client-test/CMakeLists.txt   |  3 +-
 .../ignite_node.h => client-test/src/main.cpp}     | 57 +++++++++-------------
 .../cpp/test-common/include/ignite_node.h          |  9 ++++
 .../platforms/cpp/test-common/include/process.h    | 12 ++++-
 .../platforms/cpp/test-common/src/ignite_node.cpp  | 12 +++--
 modules/platforms/cpp/test-common/src/process.cpp  | 27 +++++++---
 6 files changed, 73 insertions(+), 47 deletions(-)

diff --git a/modules/platforms/cpp/client-test/CMakeLists.txt b/modules/platforms/cpp/client-test/CMakeLists.txt
index 40c4d0df40..34202f707e 100644
--- a/modules/platforms/cpp/client-test/CMakeLists.txt
+++ b/modules/platforms/cpp/client-test/CMakeLists.txt
@@ -27,11 +27,12 @@ include_directories(${GTEST_INCLUDE_DIR})
 
 set(SOURCES
 	src/ignite_client_test.cpp
+	src/main.cpp
 )
 
 add_executable(${TARGET} ${SOURCES})
 
-target_link_libraries(${TARGET} ignite-test-common ${GTEST_LIBRARY} ${GTEST_MAIN_LIBRARY})
+target_link_libraries(${TARGET} ignite-test-common ${GTEST_LIBRARY})
 
 set(TEST_TARGET IgniteClientTest)
 add_test(NAME ${TEST_TARGET} COMMAND ${TARGET})
diff --git a/modules/platforms/cpp/test-common/include/ignite_node.h b/modules/platforms/cpp/client-test/src/main.cpp
similarity index 55%
copy from modules/platforms/cpp/test-common/include/ignite_node.h
copy to modules/platforms/cpp/client-test/src/main.cpp
index c72ac06777..1f8eeae3d6 100644
--- a/modules/platforms/cpp/test-common/include/ignite_node.h
+++ b/modules/platforms/cpp/client-test/src/main.cpp
@@ -15,39 +15,30 @@
  * limitations under the License.
  */
 
-#pragma once
+#include <chrono>
 
-#include "process.h"
+#include <gtest/gtest.h>
 
-namespace ignite
+#include "ignite_node.h"
+
+void BeforeAll()
 {
-    class IgniteNode
-    {
-    public:
-        /**
-         * Constructor.
-         */
-        IgniteNode() = default;
-
-        /**
-         * Destructor.
-         */
-        ~IgniteNode() = default;
-
-        /**
-         * Start node.
-         *
-         * @param dryRun Perform a dry run. Mostly used to ensure that code is compiled and all artifacts are downloaded.
-         */
-        void start(bool dryRun = false);
-
-        /**
-         * Stop node.
-         */
-        void stop();
-
-    private:
-        /** Underlying process. */
-        std::unique_ptr<Process> process;
-    };
-} // namespace ignite
+    ignite::IgniteNode node;
+
+    // Ignite dry run to make sure everything is built, all artifacts downloaded
+    // and Ignite node is ready to run.
+    node.start(true);
+
+    // Five minutes should be enough but feel free to increase.
+    node.join(std::chrono::minutes(5));
+    node.stop();
+}
+
+
+int main(int argc, char** argv)
+{
+    BeforeAll();
+
+    ::testing::InitGoogleTest(&argc, argv);
+    return RUN_ALL_TESTS();
+}
diff --git a/modules/platforms/cpp/test-common/include/ignite_node.h b/modules/platforms/cpp/test-common/include/ignite_node.h
index c72ac06777..10bc130b2c 100644
--- a/modules/platforms/cpp/test-common/include/ignite_node.h
+++ b/modules/platforms/cpp/test-common/include/ignite_node.h
@@ -17,6 +17,8 @@
 
 #pragma once
 
+#include <chrono>
+
 #include "process.h"
 
 namespace ignite
@@ -46,6 +48,13 @@ namespace ignite
          */
         void stop();
 
+        /**
+         * Join node process.
+         *
+         * @param timeout Timeout.
+         */
+        void join(std::chrono::milliseconds timeout);
+
     private:
         /** Underlying process. */
         std::unique_ptr<Process> process;
diff --git a/modules/platforms/cpp/test-common/include/process.h b/modules/platforms/cpp/test-common/include/process.h
index b2d6d50121..ab45700ccb 100644
--- a/modules/platforms/cpp/test-common/include/process.h
+++ b/modules/platforms/cpp/test-common/include/process.h
@@ -17,6 +17,7 @@
 
 #pragma once
 
+#include <chrono>
 #include <string>
 
 namespace ignite
@@ -44,9 +45,16 @@ namespace ignite
         virtual bool start() = 0;
 
         /**
-         * Stop process.
+         * Kill the process.
          */
-        virtual void stop() = 0;
+        virtual void kill() = 0;
+
+        /**
+         * Join process.
+         *
+         * @param timeout Timeout.
+         */
+        virtual void join(std::chrono::milliseconds timeout) = 0;
 
     protected:
         /**
diff --git a/modules/platforms/cpp/test-common/src/ignite_node.cpp b/modules/platforms/cpp/test-common/src/ignite_node.cpp
index c4c7e8a9d1..560b9f54fd 100644
--- a/modules/platforms/cpp/test-common/src/ignite_node.cpp
+++ b/modules/platforms/cpp/test-common/src/ignite_node.cpp
@@ -52,15 +52,21 @@ namespace ignite
         process = Process::make(command, workDir.string());
         if (!process->start())
         {
-            throw std::runtime_error("Failed to invoke Ignite command: '" + command + "'");
-
             process.reset();
+
+            throw std::runtime_error("Failed to invoke Ignite command: '" + command + "'");
         }
     }
 
     void IgniteNode::stop()
     {
         if (process)
-            process->stop();
+            process->kill();
+    }
+
+    void IgniteNode::join(std::chrono::milliseconds timeout)
+    {
+        if (process)
+            process->join(timeout);
     }
 } // namespace ignite
\ No newline at end of file
diff --git a/modules/platforms/cpp/test-common/src/process.cpp b/modules/platforms/cpp/test-common/src/process.cpp
index 4620b53aec..4911031bbc 100644
--- a/modules/platforms/cpp/test-common/src/process.cpp
+++ b/modules/platforms/cpp/test-common/src/process.cpp
@@ -18,7 +18,7 @@
 #ifdef WIN32
 #   include <windows.h>
 #   include <tlhelp32.h>
-#endif // WIN32
+#endif
 
 #include <filesystem>
 #include <utility>
@@ -34,7 +34,7 @@ namespace
      * @param processId ID of the parent process.
      * @return Process tree.
      */
-    std::vector<DWORD> getProcessTree(DWORD processId)
+    std::vector<DWORD> getProcessTree(DWORD processId) // NOLINT(misc-no-recursion)
     {
         std::vector<DWORD> children;
         PROCESSENTRY32 pe;
@@ -120,9 +120,9 @@ namespace
         }
 
         /**
-         * Stop process.
+         * Kill the process.
          */
-        void stop() override
+        void kill() override
         {
             std::vector<DWORD> processTree = getProcessTree(info.dwProcessId);
             for (auto procId : processTree)
@@ -137,12 +137,22 @@ namespace
 
             TerminateProcess(info.hProcess, 1);
 
-            WaitForSingleObject( info.hProcess, INFINITE );
-
             CloseHandle( info.hProcess );
             CloseHandle( info.hThread );
         }
 
+        /**
+         * Join process.
+         *
+         * @param timeout Timeout.
+         */
+        void join(std::chrono::milliseconds timeout) override
+        {
+            auto msecs = timeout.count() < 0 ? INFINITE : static_cast<DWORD>(timeout.count());
+
+            WaitForSingleObject(info.hProcess, msecs);
+        }
+
     private:
         /** Running flag. */
         bool running;
@@ -157,8 +167,9 @@ namespace
         PROCESS_INFORMATION info;
     };
 
-#else
-#endif
+#else // #ifdef WIN32
+
+#endif // #ifdef WIN32
 }
 
 namespace ignite