From: Nick Porter Date: Mon, 14 Nov 2022 18:21:25 +0000 (+0000) Subject: Use trigger to detect when server is ready in ldap_sync tests X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=16a88bd40de3606f1270b0bc1aff7c1f934b99d6;p=thirdparty%2Ffreeradius-server.git Use trigger to detect when server is ready in ldap_sync tests More reliable than just a sleep 1 --- diff --git a/src/tests/ldap_sync/active_directory/all.mk b/src/tests/ldap_sync/active_directory/all.mk index 34b161b1117..0b9f57cd9f0 100644 --- a/src/tests/ldap_sync/active_directory/all.mk +++ b/src/tests/ldap_sync/active_directory/all.mk @@ -16,12 +16,15 @@ $(eval $(call TEST_BOOTSTRAP)) include src/tests/radiusd.mk $(eval $(call RADIUSD_SERVICE,radiusd,$(OUTPUT))) +$(TEST).trigger_clear: + $(Q)rm -f $(BUILD_DIR)/tests/ldap_sync/active_directory/sync_started + # # There is a delay of up to 30 seconds looking for the output file # as samba only sends results of persistent LDAP searches on a polled # basis. Real Active Directory sends the results immediately. # -$(OUTPUT)/%: $(DIR)/% | $(TEST).radiusd_kill $(TEST).radiusd_start +$(OUTPUT)/%: $(DIR)/% | $(TEST).trigger_clear $(TEST).radiusd_kill $(TEST).radiusd_start $(eval TARGET := $(notdir $<)) $(eval EXPECTED := $(patsubst %.sh,%.out,$<)) $(eval FOUND := $(patsubst %.sh,%.out,$@)) @@ -31,7 +34,17 @@ $(OUTPUT)/%: $(DIR)/% | $(TEST).radiusd_kill $(TEST).radiusd_start $(Q)echo "LDAPSYNC-TEST active_directory $(TARGET)" $(Q)[ -f $(dir $@)/radiusd.pid ] || exit 1 $(Q)rm -f $(OUT_DIR)/$(OUT).out - $(Q)sleep 1 + +# Wait for the sync to start before applying changes + $(Q)i=0; while [ $$i -lt 100 ] ; \ + do if [ -e $(OUT_DIR)/sync_started ]; \ + then \ + break; \ + fi; \ + sleep .1; \ + i=$$((i+1)); \ + done; + $(Q)$< $(Q)i=0; while [ $$i -lt 600 ] ; \ do if [ -e $(OUT_DIR)/$(OUT).out ] ; \ diff --git a/src/tests/ldap_sync/active_directory/config/radiusd.conf b/src/tests/ldap_sync/active_directory/config/radiusd.conf index 0135f6e9823..e99eb8ed4be 100644 --- a/src/tests/ldap_sync/active_directory/config/radiusd.conf +++ b/src/tests/ldap_sync/active_directory/config/radiusd.conf @@ -40,6 +40,10 @@ global { } } +# Dummy global trigger section to enable triggers +trigger { +} + policy { linelogprep { &control.Tmp-String-0 := "%{Packet-Type} %{LDAP-Sync.DN} %{LDAP-Sync.Entry-DN} %{Proto.radius.User-Name} %{Tmp-Integer-0} %{Tmp-String-0}" @@ -128,6 +132,10 @@ server test { &Proto.radius.User-Name = 'sAMAccountName' &Tmp-Integer-0 = 'userAccountControl' } + + trigger { + start = "/usr/bin/touch ${run_dir}/sync_started" + } } sync { diff --git a/src/tests/ldap_sync/persistent_search/all.mk b/src/tests/ldap_sync/persistent_search/all.mk index f30e34c8226..384e9fa53c2 100644 --- a/src/tests/ldap_sync/persistent_search/all.mk +++ b/src/tests/ldap_sync/persistent_search/all.mk @@ -16,7 +16,10 @@ $(eval $(call TEST_BOOTSTRAP)) include src/tests/radiusd.mk $(eval $(call RADIUSD_SERVICE,radiusd,$(OUTPUT))) -$(OUTPUT)/%: $(DIR)/% | $(TEST).radiusd_kill $(TEST).radiusd_start +$(TEST).trigger_clear: + $(Q)rm -f $(BUILD_DIR)/tests/ldap_sync/persistent_search/sync_started + +$(OUTPUT)/%: $(DIR)/% | $(TEST).trigger_clear $(TEST).radiusd_kill $(TEST).radiusd_start $(eval TARGET := $(notdir $<)) $(eval EXPECTED := $(patsubst %.ldif,%.out,$<)) $(eval FOUND := $(patsubst %.ldif,%.out,$@)) @@ -27,7 +30,17 @@ $(OUTPUT)/%: $(DIR)/% | $(TEST).radiusd_kill $(TEST).radiusd_start $(Q)echo "LDAPSYNC-TEST persistent_search $(TARGET)" $(Q)[ -f $(dir $@)/radiusd.pid ] || exit 1 $(Q)rm -f $(OUT_DIR)/$(OUT).out - $(Q)sleep 1 + +# Wait for the sync to start before applying changes + $(Q)i=0; while [ $$i -lt 100 ] ; \ + do if [ -e $(OUT_DIR)/sync_started ] ; \ + then \ + break; \ + fi; \ + sleep .1; \ + i=$$((i+1)); \ + done; + $(Q)ldapmodify $(ARGV) -f $< > /dev/null $(Q)i=0; while [ $$i -lt 600 ] ; \ do if [ -e $(OUT_DIR)/$(OUT).out ] ; \ diff --git a/src/tests/ldap_sync/persistent_search/config/radiusd.conf b/src/tests/ldap_sync/persistent_search/config/radiusd.conf index f2321adfcdf..d410002177f 100644 --- a/src/tests/ldap_sync/persistent_search/config/radiusd.conf +++ b/src/tests/ldap_sync/persistent_search/config/radiusd.conf @@ -40,6 +40,10 @@ global { } } +# Dummy global trigger section to enable triggers +trigger { +} + policy { linelogprep { &request.Tmp-String-8 := &LDAP-Sync.DN @@ -140,6 +144,10 @@ server test { &Proto.radius.User-Name = 'uid' &Password.With-Header = 'userPassword' } + + trigger { + start = "/usr/bin/touch ${run_dir}/sync_started" + } } sync { diff --git a/src/tests/ldap_sync/rfc4533/all.mk b/src/tests/ldap_sync/rfc4533/all.mk index fec35fdbb49..fe7ca6636be 100644 --- a/src/tests/ldap_sync/rfc4533/all.mk +++ b/src/tests/ldap_sync/rfc4533/all.mk @@ -17,7 +17,10 @@ $(eval $(call TEST_BOOTSTRAP)) include src/tests/radiusd.mk $(eval $(call RADIUSD_SERVICE,radiusd,$(OUTPUT))) -$(OUTPUT)/%: $(DIR)/% | $(TEST).radiusd_kill $(TEST).radiusd_start +$(TEST).trigger_clear: + $(Q)rm -f $(BUILD_DIR)/tests/ldap_sync/rfc4533/sync_started + +$(OUTPUT)/%: $(DIR)/% | $(TEST).trigger_clear $(TEST).radiusd_kill $(TEST).radiusd_start $(eval TARGET := $(notdir $<)) $(eval EXPECTED := $(patsubst %.ldif,%.out,$<)) $(eval FOUND := $(patsubst %.ldif,%.out,$@)) @@ -28,7 +31,17 @@ $(OUTPUT)/%: $(DIR)/% | $(TEST).radiusd_kill $(TEST).radiusd_start $(Q)echo "LDAPSYNC-TEST rfc4533 $(TARGET)" $(Q)[ -f $(dir $@)/radiusd.pid ] || exit 1 $(Q)rm -f $(OUT_DIR)/$(OUT).out - $(Q)sleep 1 + +# Wait for the sync to start before applying changes + $(Q)i=0; while [ $$i -lt 100 ] ; \ + do if [ -e $(OUT_DIR)/sync_started ]; \ + then \ + break; \ + fi; \ + sleep .1; \ + i=$$((i+1)); \ + done ; + $(Q)ldapmodify $(ARGV) -f $< > /dev/null $(Q)i=0; while [ $$i -lt 600 ] ; \ do if [ -e $(OUT_DIR)/$(OUT).out ] ; \ diff --git a/src/tests/ldap_sync/rfc4533/config/radiusd.conf b/src/tests/ldap_sync/rfc4533/config/radiusd.conf index c96b2cd5d8f..a3b5fa5421a 100644 --- a/src/tests/ldap_sync/rfc4533/config/radiusd.conf +++ b/src/tests/ldap_sync/rfc4533/config/radiusd.conf @@ -40,6 +40,10 @@ global { } } +# Dummy global trigger section to enable triggers +trigger { +} + policy { linelogprep { &request.Tmp-String-8 := &LDAP-Sync.DN @@ -163,6 +167,10 @@ server test { &Proto.radius.User-Name = 'uid' &Password.With-Header = 'userPassword' } + + trigger { + start = "/usr/bin/touch ${run_dir}/sync_started" + } } sync {