Просмотр исходного кода

Try to make relx-start-stop more reliable

Using new wait_for_success/wait_for_failure functions that will
loop the ping commands up to 10 times then give up. This allows
us to remove the "sleep 1" and lets us handle intermittent
slowness at the same time.
Loïc Hoguin 6 лет назад
Родитель
Сommit
5e8c5fa7a0
2 измененных файлов с 31 добавлено и 7 удалено
  1. 25 0
      test/Makefile
  2. 6 7
      test/plugin_relx.mk

+ 25 - 0
test/Makefile

@@ -50,6 +50,31 @@ else
 SLEEP =
 SLEEP =
 endif
 endif
 
 
+# In some cases it is more appropriate to wait until a command succeeds or fails.
+# These functions run the given command every second and gives up after 10 tries.
+
+define wait_for_success
+	count=10; \
+	until [ $$count = 0 ] || $1; do \
+		count=`expr $$count - 1`; \
+		sleep 1; \
+	done; \
+	if [ $$count = 0 ]; then \
+		false; \
+	fi
+endef
+
+define wait_for_failure
+	count=10; \
+	while [ $$count != 0 ] && $1; do \
+		count=`expr $$count - 1`; \
+		sleep 1; \
+	done; \
+	if [ $$count = 0 ]; then \
+		false; \
+	fi
+endef
+
 # OTP master, for downloading files for testing.
 # OTP master, for downloading files for testing.
 
 
 OTP_MASTER = https://raw.githubusercontent.com/erlang/otp/master
 OTP_MASTER = https://raw.githubusercontent.com/erlang/otp/master

+ 6 - 7
test/plugin_relx.mk

@@ -301,28 +301,27 @@ ifeq ($(PLATFORM),msys2)
 	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) install
 	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) install
 endif
 endif
 	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) start
 	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) start
-	$t sleep 1
 
 
 	$i "Ping the release"
 	$i "Ping the release"
-	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) ping
+	$t $(call wait_for_success,$(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) ping)
 
 
 	$i "Stop the release"
 	$i "Stop the release"
 	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) stop
 	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) stop
-	$t sleep 1
 ifeq ($(PLATFORM),msys2)
 ifeq ($(PLATFORM),msys2)
+	$t sleep 1
 	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) uninstall
 	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) uninstall
 endif
 endif
 
 
-	$i "Check that there's no erl_crash.dump file"
-	$t test ! -f $(APP)/_rel/$(APP)_release/erl_crash.dump
-
 ifneq ($(PLATFORM),msys2)
 ifneq ($(PLATFORM),msys2)
 # The script will not return false on Windows when the ping fails.
 # The script will not return false on Windows when the ping fails.
 # It sometimes also gets stuck. So we just skip the ping for now.
 # It sometimes also gets stuck. So we just skip the ping for now.
 	$i "Check that further pings get no replies"
 	$i "Check that further pings get no replies"
-	$t ! $(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) ping
+	$t $(call wait_for_failure,$(APP)/_rel/$(APP)_release/bin/$(APP)_release$(RELX_REL_EXT) ping)
 endif
 endif
 
 
+	$i "Check that there's no erl_crash.dump file"
+	$t test ! -f $(APP)/_rel/$(APP)_release/erl_crash.dump
+
 relx-tar: init
 relx-tar: init
 
 
 	$i "Bootstrap a new release named $(APP)"
 	$i "Bootstrap a new release named $(APP)"