Repository navigation
Added reactor tests to make check #6447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
larsewi
merged 4 commits into
cfengine:master
from
victormlg:cf-reactor.RunTestsInJenkins
Oct 30, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
37beeca
Run reactor tests in jenkins
victormlg 5f352d3
Added better logging of the cf-reactor tests
victormlg 51a2014
Fixed out of range scalar value for guest environments
victormlg 045402d
Fixed cf-reactor users test failing when run as root
victormlg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # | ||
| # Copyright 2026 Northern.tech AS | ||
| # | ||
| # This file is part of CFEngine 3 - written and maintained by Northern.tech AS. | ||
| # | ||
| # This program is free software; you can redistribute it and/or modify it | ||
| # under the terms of the GNU General Public License as published by the | ||
| # Free Software Foundation; version 3. | ||
| # | ||
| # This program is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with this program; if not, write to the Free Software | ||
| # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA | ||
| # | ||
| # To the extent this program is licensed as part of the Enterprise | ||
| # versions of CFEngine, the applicable Commercial Open Source License | ||
| # (COSL) may apply to this file if you as a licensee so wish it. See | ||
| # included file COSL.txt. | ||
| # | ||
|
|
||
| # The test scripts, with their policy next to them | ||
| REACTOR_TEST_SH = $(sort $(wildcard \ | ||
| $(srcdir)/tests/*/*.sh \ | ||
| $(srcdir)/tests/*/unsafe/*.sh)) | ||
| REACTOR_TEST_CF = $(REACTOR_TEST_SH:.sh=.cf) | ||
|
|
||
| # cf-reactor is not built with builtin extensions (e.g. on Windows) | ||
| if !BUILTIN_EXTENSIONS | ||
| TESTS = $(patsubst $(srcdir)/%,%,$(REACTOR_TEST_SH)) | ||
| endif | ||
|
|
||
| # Each test is run by run_test.sh, with the binaries of this build. The ones | ||
| # in an unsafe/ directory are skipped unless UNSAFE_TESTS=1. | ||
| TESTS_ENVIRONMENT = env \ | ||
| CF_REACTOR=$(abs_top_builddir)/cf-reactor/cf-reactor \ | ||
| CF_PROMISES=$(abs_top_builddir)/cf-promises/cf-promises \ | ||
| $(SHELL) $(srcdir)/run_test.sh | ||
|
|
||
| EXTRA_DIST = lib.cf lib.sh run.sh run_test.sh \ | ||
| $(patsubst $(srcdir)/%,%,$(REACTOR_TEST_SH) $(REACTOR_TEST_CF)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,89 @@ | ||
| # Helpers sourced by the tests. Expects CF_REACTOR and LOG to be exported by | ||
| # run.sh. | ||
| # run_test.sh. | ||
| # | ||
| # Only POSIX tools are used, as the tests are run on all the platforms (e.g. | ||
| # no timeout(1), grep -m or date +%s). | ||
|
|
||
| # Seconds to wait for something before giving up | ||
| WAIT_TIMEOUT=60 | ||
|
|
||
| # number of log lines already consumed by wait_for_log | ||
| log_offset=0 | ||
|
|
||
| # Run command $@ until it succeeds, for at most WAIT_TIMEOUT seconds, polling | ||
| # every 0.1 second, or every second where sleep only takes whole seconds. | ||
| # Fails if it never succeeded. Runs in a subshell without tracing, so that | ||
| # set -x doesn't log every poll. | ||
| wait_until() { | ||
| ( | ||
| set +x | ||
| if sleep 0.1 2>/dev/null; then | ||
| interval=0.1 polls=$((WAIT_TIMEOUT * 10)) | ||
| else | ||
| interval=1 polls=$WAIT_TIMEOUT | ||
| fi | ||
| until "$@"; do | ||
| [ "$polls" -gt 0 ] || exit 1 | ||
| polls=$((polls - 1)) | ||
| sleep "$interval" | ||
| done | ||
| ) | ||
| } | ||
|
|
||
| # Print the current time in seconds since the Epoch. date +%s is not POSIX; | ||
| # without it, srand() seeds with the time of day and returns the last seed. | ||
|
Comment on lines
+33
to
+34
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here? |
||
| now() { | ||
| t=$(date +%s 2>/dev/null) | ||
| case "$t" in | ||
| ''|*[!0-9]*) awk 'BEGIN { srand(); print srand() }' ;; | ||
| *) echo "$t" ;; | ||
| esac | ||
| } | ||
|
|
||
| # Print the first line of the reactor log after line $1 that contains $2, | ||
| # prefixed with its number counted from line $1. Fails if there is none. | ||
| log_match() { | ||
| tail -n "+$(($1 + 1))" "$LOG" 2>/dev/null | grep -n -F -- "$2" | head -n 1 | grep . | ||
| } | ||
|
|
||
| # Fail unless the reactor log contains $1. | ||
| log_contains() { | ||
| grep -q -F -- "$1" "$LOG" 2>/dev/null | ||
| } | ||
|
|
||
| # Print the number of lines of file $1, 0 if it doesn't exist. | ||
| count_lines() { | ||
| if [ -f "$1" ]; then | ||
| # without the padding of some wc implementations | ||
| echo $(( $(wc -l < "$1") )) | ||
| else | ||
| echo 0 | ||
| fi | ||
| } | ||
|
|
||
| # Fail unless file $1 has at least $2 lines. | ||
| has_lines() { | ||
| [ "$(count_lines "$1")" -ge "$2" ] | ||
| } | ||
|
|
||
| # Wait until the reactor log contains $1 in a line after the last match, then | ||
| # skip past that line, so that the next wait only sees newer output. | ||
| wait_for_log() { | ||
| if ! match=$(timeout 60 sh -c ' | ||
| until tail -n "+$(($2 + 1))" "$1" | grep -n -F -m 1 -- "$3"; do | ||
| sleep 0.1 | ||
| done' _ "$LOG" "$log_offset" "$1") | ||
| if ! wait_until log_match "$log_offset" "$1" >/dev/null | ||
| then | ||
| echo "Timed out waiting for '$1' in reactor log:" >&2 | ||
| cat "$LOG" >&2 | ||
| return 1 | ||
| fi | ||
| match=$(log_match "$log_offset" "$1") | ||
| log_offset=$((log_offset + ${match%%:*})) | ||
| } | ||
|
|
||
| # Wait until cf-reactor has registered the watchers of the policy, $1 of them. | ||
| # The watcher thread may log before this line, so search the whole log and | ||
| # leave the offset of wait_for_log as is. | ||
| wait_for_watchers() { | ||
| if ! timeout 60 sh -c ' | ||
| until grep -q -F -- "$2" "$1"; do | ||
| sleep 0.1 | ||
| done' _ "$LOG" "verbose: cf-reactor event watcher has $1 watcher(s)" | ||
| if ! wait_until log_contains "verbose: cf-reactor event watcher has $1 watcher(s)" | ||
| then | ||
| echo "Timed out waiting for $1 watcher(s) in reactor log:" >&2 | ||
| cat "$LOG" >&2 | ||
|
|
@@ -36,17 +93,14 @@ wait_for_watchers() { | |
|
|
||
| # Wait until file $1 has at least $2 lines, then fail if it has more than $2. | ||
| wait_for_lines() { | ||
| if ! timeout 60 sh -c ' | ||
| until [ "$(cat "$1" 2>/dev/null | wc -l)" -ge "$2" ]; do | ||
| sleep 0.1 | ||
| done' _ "$1" "$2" | ||
| if ! wait_until has_lines "$1" "$2" | ||
| then | ||
| echo "Timed out waiting for $2 line(s) in '$1', reactor log:" >&2 | ||
| cat "$LOG" >&2 | ||
| return 1 | ||
| fi | ||
|
|
||
| lines=$(wc -l < "$1") | ||
| lines=$(count_lines "$1") | ||
| if [ "$lines" -ne "$2" ] | ||
| then | ||
| echo "Expected $2 line(s) in '$1', got $lines" >&2 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this a problem on any of the supported platforms?