Skip to content

Commit

Permalink
Add script and CICD job for testing CLI startup time (#706)
Browse files Browse the repository at this point in the history
  • Loading branch information
juhoinkinen authored May 22, 2023
1 parent 6f13121 commit 4f6994b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ jobs:
run: |
poetry run flake8
time-startup:
runs-on: ubuntu-22.04
name: check CLI startup time
steps:
- uses: actions/checkout@v3
- name: "Prepare: restore caches, install Poetry, set up Python"
id: prepare
uses: ./.github/actions/prepare
with:
python-version: "3.9"
poetry-version: ${{ env.POETRY_VERSION }}
- name: Install Python dependencies
run: |
poetry install
- name: Check startup time
run: |
poetry run tests/time-startup.sh
test:
runs-on: ubuntu-22.04
timeout-minutes: 15
Expand Down
27 changes: 27 additions & 0 deletions tests/time-startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# Function to measure startup time
measure_startup_time() {
startup_time=$( { time -p annif --help >/dev/null; } 2>&1 | awk '/^user/{u=$2}/^sys/{s=$2} END{print u+s}' )
echo "$startup_time"
}

startup_time1=$(measure_startup_time)
startup_time2=$(measure_startup_time)
startup_time3=$(measure_startup_time)
startup_time4=$(measure_startup_time)

# Calculate the average startup time
average_startup_time=$(echo "scale=3; ($startup_time1 + $startup_time2 + $startup_time3 + $startup_time4) / 4" | bc)

# Print the average startup time
echo "Average Startup time: $average_startup_time seconds"

# Set the threshold for acceptable startup time in seconds
threshold=0.300

# Compare the average startup time with the threshold
if (( $(echo "$average_startup_time > $threshold" | bc -l) )); then
echo "Startup time (user + sys time) exceeds the threshold of $threshold s. Test failed."
exit 1
fi

0 comments on commit 4f6994b

Please sign in to comment.