Skip to content

Commit

Permalink
Add timeout when running tests to prevent loops
Browse files Browse the repository at this point in the history
  • Loading branch information
laurenthuberdeau committed Aug 30, 2024
1 parent 65a64f2 commit 982bcce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
23 changes: 16 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2

- name: Install utils
run: |
if [ ${{ matrix.host }} = "macos-latest" ]; then
brew install coreutils
else
sudo apt-get update
sudo apt-get install -y coreutils
fi
- name: Run ${{ matrix.target }} tests on ${{ matrix.host }}
run: |
set -e
Expand All @@ -38,12 +47,12 @@ jobs:
- name: Install ${{ matrix.shell }} shell
run: |
sudo apt-get update
sudo apt-get install -y bash ${{ matrix.shell }}
sudo apt-get install -y coreutils ${{ matrix.shell }}
- name: Run tests with ${{ matrix.shell }}
run: |
set -e
bash ./run-tests.sh sh --shell ${{ matrix.shell }}
./run-tests.sh sh --shell ${{ matrix.shell }}
bootstrap-pnut-sh:
strategy:
Expand All @@ -57,12 +66,12 @@ jobs:
- name: Install ${{ matrix.shell }} shell
run: |
sudo apt-get update
sudo apt-get install -y bash ${{ matrix.shell }}
sudo apt-get install -y coreutils ${{ matrix.shell }}
- name: Bootstrap pnut.sh on ${{ matrix.shell }}
run: |
set -e
bash ./bootstrap-pnut.sh --shell ${{ matrix.shell }} --fast
./bootstrap-pnut.sh --shell ${{ matrix.shell }} --fast
bootstrap-pnut-exe:
strategy:
Expand All @@ -84,10 +93,10 @@ jobs:
- name: Install ${{ matrix.shell }} shell
run: |
if [ ${{ matrix.host }} = "macos-latest" ]; then
brew install ${{ matrix.shell }}
brew install coreutils ${{ matrix.shell }}
else
sudo apt-get update
sudo apt-get install -y ${{ matrix.shell }}
sudo apt-get install -y coreutils ${{ matrix.shell }}
fi
- name: Bootstrap pnut-exe with ${{ matrix.target }} backend
Expand Down Expand Up @@ -117,7 +126,7 @@ jobs:
# Check that the woody environment has the right bash version
sudo chroot woody /bin/bash -c "bash --version" | grep 2.05a || { echo "Bash 2.05a is required for this job"; exit 1; }
sudo chroot woody /bin/bash -c "mkdir pnut && tar -xvzf pnut.tar.gz -C pnut" # Extract the pnut repo into the woody environment
sudo chroot woody /bin/bash -c "apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential time" # Install gcc and time utils
sudo chroot woody /bin/bash -c "apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential time timeout" # Install gcc and time utils
- name: Run tests with bash 2.05a
run: |
Expand Down
5 changes: 3 additions & 2 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ test_expect_failure_for_shell() { # file: $1

execute_test() { # executable: $1, args: $2 ...
if [ "$backend" = "sh" ]; then
$shell "./$1" $2
# Use a 30s timeout to prevent infinite loops
timeout 30 $shell "./$1" $2
else
"./$1" $2
timeout 5 "./$1" $2
fi
}

Expand Down

0 comments on commit 982bcce

Please sign in to comment.