Skip to content

Commit

Permalink
feat: feature flag enable parallel only macos and ubuntu
Browse files Browse the repository at this point in the history
  • Loading branch information
Chemaclass committed Oct 13, 2024
1 parent 61dc052 commit d35cbf7
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 19 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:

simple-output:
name: "On ${{ matrix.os }} - simple & sync"
name: "${{ matrix.os }} - simple & sync"
timeout-minutes: 10
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -28,7 +28,7 @@ jobs:
./bashunit --simple --no-parallel tests/
simple-output-parallel:
name: "On ${{ matrix.os }} - simple & parallel"
name: "${{ matrix.os }} - simple & parallel"
timeout-minutes: 10
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -47,7 +47,7 @@ jobs:
./bashunit --simple --parallel tests/
detailed-output-parallel:
name: "On ${{ matrix.os }} - detailed & parallel"
name: "${{ matrix.os }} - detailed & parallel"
timeout-minutes: 10
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -66,7 +66,7 @@ jobs:
./bashunit --detailed --parallel tests/
windows:
name: "On windows (${{ matrix.test_chunk }})"
name: "windows (${{ matrix.test_chunk }})"
timeout-minutes: 10
runs-on: windows-latest
strategy:
Expand All @@ -85,7 +85,7 @@ jobs:
./bashunit tests/${{ matrix.test_chunk }}/*_test.sh
alpine:
name: "On alpine-latest"
name: "alpine-latest"
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased](https://github.com/TypedDevs/bashunit/compare/0.17.0...main)

- Added `-p|--parallel` to enable running tests in parallel
- Enabled only in macOS and Ubuntu
- Added `assert_file_contains` and `assert_file_not_contains`
- Added `assert_true` and `assert_false`
- Added `BASHUNIT_DEV_LOG`
Expand Down
16 changes: 9 additions & 7 deletions src/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,25 @@ function main::exec_tests() {
trap 'main::cleanup' SIGINT
trap '[[ $? -eq $EXIT_CODE_STOP_ON_FAILURE ]] && main::handle_stop_on_failure_sync' EXIT

if env::is_parallel_run_enabled && check_os::is_alpine; then
printf "%sWarning: Parallel test execution on Alpine Linux is currently" "${_COLOR_INCOMPLETE}"
printf "in a beta stage.\nThis means there may be unresolved issues, "
printf "particularly involving race conditions.%s\n" "${_COLOR_DEFAULT}"
if env::is_parallel_run_enabled && ! parallel::is_enabled; then
printf "%sWarning: Parallel tests are working only for macOS and Ubuntu.\n" "${_COLOR_INCOMPLETE}"
printf "For other OS (Linux/Alpine, Windows), --parallel is not enabled due to inconsistent results,\n"
printf "particularly involving race conditions.%s " "${_COLOR_DEFAULT}"
printf "%sFallback using --no-parallel%s\n" "${_COLOR_SKIPPED}" "${_COLOR_DEFAULT}"
fi

if env::is_parallel_run_enabled; then
if parallel::is_enabled; then
parallel::reset
fi

console_header::print_version_with_env "$filter" "${test_files[@]}"
runner::load_test_files "$filter" "${test_files[@]}"
if env::is_parallel_run_enabled; then

if parallel::is_enabled; then
wait
fi

if env::is_parallel_run_enabled && parallel::must_stop_on_failure; then
if parallel::is_enabled && parallel::must_stop_on_failure; then
printf "\r%sStop on failure enabled...%s\n" "${_COLOR_SKIPPED}" "${_COLOR_DEFAULT}"
fi

Expand Down
5 changes: 5 additions & 0 deletions src/parallel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,8 @@ function parallel::reset() {
rm -rf "$TEMP_DIR_PARALLEL_TEST_SUITE"
[ -f "$TEMP_FILE_PARALLEL_STOP_ON_FAILURE" ] && rm "$TEMP_FILE_PARALLEL_STOP_ON_FAILURE"
}

function parallel::is_enabled() {
[[ $(env::is_parallel_run_enabled) \
&& ($(check_os::is_macos) || $(check_os::is_ubuntu)) ]]
}
12 changes: 6 additions & 6 deletions src/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function runner::load_test_files() {
# shellcheck source=/dev/null
source "$test_file"
runner::run_set_up_before_script
if env::is_parallel_run_enabled; then
if parallel::is_enabled; then
runner::call_test_functions "$test_file" "$filter" 2>/dev/null &
else
runner::call_test_functions "$test_file" "$filter"
Expand All @@ -22,7 +22,7 @@ function runner::load_test_files() {
runner::clean_set_up_and_tear_down_after_script
done

if env::is_parallel_run_enabled; then
if parallel::is_enabled; then
wait
runner::spinner &
local spinner_pid=$!
Expand Down Expand Up @@ -74,14 +74,14 @@ function runner::call_test_functions() {
return
fi

if ! env::is_simple_output_enabled && ! env::is_parallel_run_enabled; then
if ! env::is_simple_output_enabled && ! parallel::is_enabled; then
echo "Running $script"
fi

helper::check_duplicate_functions "$script" || true

for function_name in "${functions_to_run[@]}"; do
if env::is_parallel_run_enabled && parallel::must_stop_on_failure; then
if parallel::is_enabled && parallel::must_stop_on_failure; then
break
fi

Expand Down Expand Up @@ -193,7 +193,7 @@ function runner::run_test() {
runner::write_failure_result_output "$test_file" "$subshell_output"

if env::is_stop_on_failure_enabled; then
if env::is_parallel_run_enabled; then
if parallel::is_enabled; then
parallel::mark_stop_on_failure
else
exit "$EXIT_CODE_STOP_ON_FAILURE"
Expand Down Expand Up @@ -249,7 +249,7 @@ function runner::parse_result() {
shift
local args=("$@")

if env::is_parallel_run_enabled; then
if parallel::is_enabled; then
runner::parse_result_parallel "$function_name" "$execution_result" "${args[@]}"
else
runner::parse_result_sync "$function_name" "$execution_result"
Expand Down
2 changes: 1 addition & 1 deletion src/state.sh
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ function state::print_line() {
*) char="?" && log "warning" "unknown test type '$type'" ;;
esac

if env::is_parallel_run_enabled; then
if parallel::is_enabled; then
printf "%s" "$char"
else
if (( _TOTAL_TESTS_COUNT % 50 == 0 )); then
Expand Down

0 comments on commit d35cbf7

Please sign in to comment.