From 2b9b080c8068563533705569d2e8d90affb0b5f0 Mon Sep 17 00:00:00 2001
From: Sergey Yakubov <sergey.yakubov@desy.de>
Date: Mon, 24 May 2021 10:29:19 +0200
Subject: [PATCH] update win tests

---
 CMakeModules/prepare_asapo.cmake              |  2 ++
 .../broker/get_last/check_windows.bat         |  9 ++-----
 .../broker/get_meta/check_windows.bat         |  9 ++-----
 .../broker/get_next/check_windows.bat         |  9 ++-----
 .../common_scripts/start_authorizer.bat       | 24 +++++++++++++++++++
 .../common_scripts/start_services.bat         |  8 +++++++
 .../common_scripts/stop_authorizer.bat        |  3 +++
 7 files changed, 43 insertions(+), 21 deletions(-)
 create mode 100644 tests/automatic/common_scripts/start_authorizer.bat
 create mode 100644 tests/automatic/common_scripts/stop_authorizer.bat

diff --git a/CMakeModules/prepare_asapo.cmake b/CMakeModules/prepare_asapo.cmake
index 7ef66d96f..66c7e5251 100644
--- a/CMakeModules/prepare_asapo.cmake
+++ b/CMakeModules/prepare_asapo.cmake
@@ -27,6 +27,8 @@ function(prepare_asapo)
         configure_file(${CMAKE_SOURCE_DIR}/tests/automatic/settings/authorizer_settings.json.tpl.win authorizer.json.tpl COPYONLY)
         configure_file(${CMAKE_SOURCE_DIR}/tests/automatic/common_scripts/start_services.bat start_services.bat COPYONLY)
         configure_file(${CMAKE_SOURCE_DIR}/tests/automatic/common_scripts/stop_services.bat stop_services.bat COPYONLY)
+        configure_file(${CMAKE_SOURCE_DIR}/tests/automatic/common_scripts/start_authorizer.bat start_authorizer.bat COPYONLY)
+        configure_file(${CMAKE_SOURCE_DIR}/tests/automatic/common_scripts/stop_authorizer.bat stop_authorizer.bat COPYONLY)
 
         configure_file(${CMAKE_SOURCE_DIR}/config/nomad/receiver_tcp.nmd.in  receiver_tcp.nmd @ONLY)
         configure_file(${CMAKE_SOURCE_DIR}/config/nomad/nginx_kill_win.nmd nginx_kill.nmd @ONLY)
diff --git a/tests/automatic/broker/get_last/check_windows.bat b/tests/automatic/broker/get_last/check_windows.bat
index 6ffe451b5..0de73dda4 100644
--- a/tests/automatic/broker/get_last/check_windows.bat
+++ b/tests/automatic/broker/get_last/check_windows.bat
@@ -7,10 +7,7 @@ echo db.data_default.insert({"_id":2}) | %mongo_exe% %database_name%  || goto :e
 set full_name="%1"
 set short_name="%~nx1"
 
-c:\opt\consul\nomad run authorizer.nmd
-c:\opt\consul\nomad run nginx.nmd
-
-ping 192.0.2.1 -n 1 -w 2000 > nul
+call start_authorizer.bat
 
 
 start /B "" "%full_name%" -config settings.json
@@ -53,6 +50,4 @@ exit /b 1
 Taskkill /IM "%short_name%" /F
 echo db.dropDatabase() | %mongo_exe% %database_name%
 del /f groupid
-c:\opt\consul\nomad stop authorizer
-c:\opt\consul\nomad stop nginx
-c:\opt\consul\nomad run nginx_kill.nmd  && c:\opt\consul\nomad stop -yes -purge nginx_kill
+call stop_authorizer.bat
diff --git a/tests/automatic/broker/get_meta/check_windows.bat b/tests/automatic/broker/get_meta/check_windows.bat
index c5dab94bb..9e1e9e8d9 100644
--- a/tests/automatic/broker/get_meta/check_windows.bat
+++ b/tests/automatic/broker/get_meta/check_windows.bat
@@ -6,10 +6,7 @@ echo db.meta.insert({"_id":0}) | %mongo_exe% %database_name%  || goto :error
 set full_name="%1"
 set short_name="%~nx1"
 
-c:\opt\consul\nomad run authorizer.nmd
-c:\opt\consul\nomad run nginx.nmd
-
-ping 192.0.2.1 -n 1 -w 2000 > nul
+call start_authorizer.bat
 
 start /B "" "%full_name%" -config settings.json
 
@@ -32,6 +29,4 @@ exit /b 1
 Taskkill /IM "%short_name%" /F
 echo db.dropDatabase() | %mongo_exe% %database_name%
 del /f groupid
-c:\opt\consul\nomad stop authorizer
-c:\opt\consul\nomad stop nginx
-c:\opt\consul\nomad run nginx_kill.nmd  && c:\opt\consul\nomad stop -yes -purge nginx_kill
+call stop_authorizer.bat
diff --git a/tests/automatic/broker/get_next/check_windows.bat b/tests/automatic/broker/get_next/check_windows.bat
index 81330cd76..b32059d4f 100644
--- a/tests/automatic/broker/get_next/check_windows.bat
+++ b/tests/automatic/broker/get_next/check_windows.bat
@@ -9,10 +9,7 @@ set short_name="%~nx1"
 
 set token=%BT_DATA_TOKEN%
 
-c:\opt\consul\nomad run authorizer.nmd
-c:\opt\consul\nomad run nginx.nmd
-
-ping 192.0.2.1 -n 1 -w 2000 > nul
+call start_authorizer.bat
 
 start /B "" "%full_name%" -config settings.json
 
@@ -39,6 +36,4 @@ Taskkill /IM "%short_name%" /F
 echo db.dropDatabase() | %mongo_exe% %database_name%
 del /f token
 del /f groupid
-c:\opt\consul\nomad stop authorizer
-c:\opt\consul\nomad stop nginx
-c:\opt\consul\nomad run nginx_kill.nmd  && c:\opt\consul\nomad stop -yes -purge nginx_kill
+call stop_authorizer.bat
diff --git a/tests/automatic/common_scripts/start_authorizer.bat b/tests/automatic/common_scripts/start_authorizer.bat
new file mode 100644
index 000000000..de5ada62f
--- /dev/null
+++ b/tests/automatic/common_scripts/start_authorizer.bat
@@ -0,0 +1,24 @@
+c:\opt\consul\nomad run authorizer.nmd
+c:\opt\consul\nomad run nginx.nmd
+
+ping 192.0.2.1 -n 1 -w 3000 > nul
+
+set i=0
+:repeat
+set /a i=%i%+1
+echo %i%
+if %i% EQU 20 (
+    goto :error
+)
+ping 192.0.2.1 -n 1 -w 1000 >nul
+curl --silent --data "" 127.0.0.1:8400/asapo-authorizer/authorize --stderr -  | findstr /c:"Bad Request" || goto :repeat
+echo asapo services ready
+
+goto :clean
+
+:error
+echo error starting  asapo services
+call :clean
+exit /b 1
+
+:clean
diff --git a/tests/automatic/common_scripts/start_services.bat b/tests/automatic/common_scripts/start_services.bat
index cbe15b437..452c5937b 100644
--- a/tests/automatic/common_scripts/start_services.bat
+++ b/tests/automatic/common_scripts/start_services.bat
@@ -20,3 +20,11 @@ curl --silent --fail 127.0.0.1:8400/asapo-discovery/v0.1/asapo-receiver?protocol
 curl --silent --fail 127.0.0.1:8400/asapo-discovery/v0.1/asapo-broker?protocol=v0.1 --stderr - | findstr 127.0.0.1 || goto :repeat
 curl --silent --fail 127.0.0.1:8400/asapo-discovery/v0.1/asapo-file-transfer?protocol=v0.1 --stderr -  | findstr 127.0.0.1 || goto :repeat
 echo discovery ready
+
+goto :clean
+
+:error
+echo error starting  asapo services
+exit /b 1
+
+:clean
diff --git a/tests/automatic/common_scripts/stop_authorizer.bat b/tests/automatic/common_scripts/stop_authorizer.bat
new file mode 100644
index 000000000..27b0b30b9
--- /dev/null
+++ b/tests/automatic/common_scripts/stop_authorizer.bat
@@ -0,0 +1,3 @@
+c:\opt\consul\nomad stop authorizer
+c:\opt\consul\nomad stop nginx
+c:\opt\consul\nomad run nginx_kill.nmd  && c:\opt\consul\nomad stop -yes -purge nginx_kill
-- 
GitLab