Skip to content

Commit

Permalink
Merge pull request #434 from martin-schulze-vireso/bugfix/issue-433
Browse files Browse the repository at this point in the history
Fix rm semaphores/slot-: No such file or directory in parallel mode on MacOS
  • Loading branch information
martin-schulze-vireso committed Apr 25, 2021
2 parents e49b372 + 804fd32 commit fba8ff6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ The format is based on [Keep a Changelog][kac] and this project adheres to
* avoid collisions on `$BATS_RUN_TMPDIR` with `--no-tempdir-cleanup` and docker
by using `mktemp` additionally to PID (#409)
* pretty printer now puts text that is printed to FD 3 below the test name (#426)
* `rm semaphores/slot-: No such file or directory` in parallel mode on MacOS
(#434, #433)

## [1.3.0] - 2021-03-08

Expand Down
4 changes: 3 additions & 1 deletion lib/bats-core/semaphore.bash
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ elif command -v shlock >/dev/null; then
done
# we got the lock now, execute the command
"$@"
local status=$?
# free the lock
rm -f "$lockfile"
return $status
}
fi

Expand Down Expand Up @@ -98,4 +100,4 @@ bats_semaphore_get_free_slot_count() {
echo $(( BATS_SEMAPHORE_NUMBER_OF_SLOTS - used_slots ))
}

export -f bats_semaphore_get_free_slot_count
export -f bats_semaphore_get_free_slot_count
8 changes: 8 additions & 0 deletions test/bats.bats
Original file line number Diff line number Diff line change
Expand Up @@ -795,3 +795,11 @@ EOF
BATS_TMPDIR="${BATS_RUN_TMPDIR}" expected="/tmp" run bats "$FIXTURE_ROOT/BATS_TMPDIR.bats"
[ "$status" -eq 0 ]
}

@test "Parallel mode works on MacOS with over subscription (issue #433)" {
type -p parallel &>/dev/null || skip "--jobs requires GNU parallel"
run bats -j 2 "$FIXTURE_ROOT/issue-433"

[ "$status" -eq 0 ]
[[ "$output" != *"No such file or directory"* ]] || exit 1 # ensure failures are detected with old bash
}
8 changes: 8 additions & 0 deletions test/fixtures/bats/issue-433/repro1.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@test "1" {
sleep 1
}

@test "2" {
sleep 1
}

8 changes: 8 additions & 0 deletions test/fixtures/bats/issue-433/repro2.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@test "11" {
sleep 1
}

@test "12" {
sleep 1
}

0 comments on commit fba8ff6

Please sign in to comment.