Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Fix some test flakiness (#1228)
Browse files Browse the repository at this point in the history
Fix some test flakiness
  • Loading branch information
lbonn authored Jun 13, 2019
2 parents ba0e4b2 + 326fc3d commit 720cb70
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 39 deletions.
1 change: 1 addition & 0 deletions docker/Dockerfile.debian.testing
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ RUN apt-get update && apt-get -y install \
libtool \
lshw \
make \
net-tools \
opensc \
pkg-config \
psmisc \
Expand Down
1 change: 1 addition & 0 deletions docker/Dockerfile.ubuntu.bionic
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ RUN apt-get update && apt-get -y install \
lshw \
make \
opensc \
net-tools \
pkg-config \
psmisc \
python3-dev \
Expand Down
1 change: 1 addition & 0 deletions docker/Dockerfile.ubuntu.xenial
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ RUN apt-get update && apt-get -y install \
libtool \
lshw \
make \
net-tools \
opensc \
pkg-config \
psmisc \
Expand Down
3 changes: 1 addition & 2 deletions scripts/make_ostree_sysroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ fi

SCRIPT="${1}/tests/ostree-scripts/makephysical.sh"
REPO="${2}/ostree_repo"
PORT=$("${1}/tests/get_open_port.py")

if [ ! -d "${REPO}" ]; then
"${SCRIPT}" "${REPO}" ${PORT}
"${SCRIPT}" "${REPO}"
fi
7 changes: 3 additions & 4 deletions src/aktualizr_lite/test_lite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ akrepo_bin=$2
tests_dir=$3
#valgrind=$4
valgrind=""
port=$($tests_dir/get_open_port.py)

dest_dir=$(mktemp -d)

Expand Down Expand Up @@ -49,10 +48,10 @@ add_target foo2
akrepo --command signtargets

pushd $dest_dir
python3 -m http.server $port &
python3 -m http.server 0&
pid=$!

# curl http://localhost:$port/repo/image/targets.json | json_pp
port=$("$tests_dir/find_listening_port.sh" "$pid")
echo "http server listening on $port"

export OSTREE_SYSROOT=$dest_dir/sysroot
mkdir $OSTREE_SYSROOT
Expand Down
4 changes: 2 additions & 2 deletions src/libaktualizr/primary/aktualizr_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ TEST(Aktualizr, FinalizationFailure) {
EXPECT_EQ(current_version, SIZE_MAX);

auto aktualizr_cycle_thread = aktualizr.RunForever();
auto aktualizr_cycle_thread_status = aktualizr_cycle_thread.wait_for(std::chrono::seconds(10));
auto aktualizr_cycle_thread_status = aktualizr_cycle_thread.wait_for(std::chrono::seconds(20));

ASSERT_EQ(aktualizr_cycle_thread_status, std::future_status::ready);
EXPECT_TRUE(aktualizr.uptane_client_->bootloader->rebootDetected());
Expand Down Expand Up @@ -931,7 +931,7 @@ TEST(Aktualizr, AutoRebootAfterUpdate) {

aktualizr.Initialize();
auto aktualizr_cycle_thread = aktualizr.RunForever();
auto aktualizr_cycle_thread_status = aktualizr_cycle_thread.wait_for(std::chrono::seconds(10));
auto aktualizr_cycle_thread_status = aktualizr_cycle_thread.wait_for(std::chrono::seconds(20));

EXPECT_EQ(aktualizr_cycle_thread_status, std::future_status::ready);
EXPECT_TRUE(aktualizr.uptane_client_->bootloader->rebootDetected());
Expand Down
17 changes: 17 additions & 0 deletions tests/find_listening_port.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

set -euo pipefail

# returns the tcp port a server application listens to
# dependency: netstat (net-tools)

pid=$1

port=
try=0
while [[ -z $port && $try -le 100 ]]; do
port=$(netstat -lpan 2> /dev/null | awk -F '[ :]+' "/$pid\\/python3/ {print \$5}")
sleep 0.2
try=$((try+1))
done
echo "$port"
17 changes: 0 additions & 17 deletions tests/get_open_port.py

This file was deleted.

18 changes: 6 additions & 12 deletions tests/ostree-scripts/makephysical.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rm -rf "$OSTREE_SYSROOT"
mkdir -p "$OSTREE_SYSROOT"
ostree admin init-fs "$OSTREE_SYSROOT"
ostree admin os-init $OSNAME
ostree config --repo=${OSTREE_SYSROOT}/ostree/repo set core.mode bare-user-only
ostree config --repo="${OSTREE_SYSROOT}/ostree/repo" set core.mode bare-user-only

mkdir -p "$OSTREE_SYSROOT/boot/loader.0"
ln -s loader.0 "$OSTREE_SYSROOT/boot/loader"
Expand All @@ -29,25 +29,19 @@ SCRIPT_DIR="$(dirname "$0")"
OSTREE_DIR=$(mktemp -d /tmp/ostreephys-XXXXXX)
"$SCRIPT_DIR/makedeployed.sh" "$OSTREE_DIR/repo" $BRANCHNAME $HARDWARE

if [ "$#" -eq 2 ]; then
echo "port: $2"
PORT=$2
else
PORT=56042
fi

(
cd "$OSTREE_DIR/repo"

python3 -m http.server $PORT &
python3 -m http.server 0 &
PORT=$("$SCRIPT_DIR/../find_listening_port.sh" $!)
trap 'kill %1' EXIT

# Wait for http server to start serving. This can take a while sometimes.
until curl 127.0.0.1:$PORT &> /dev/null
do
until curl 127.0.0.1:"$PORT" &> /dev/null; do
sleep 0.2
done

ostree --repo="$OSTREE_SYSROOT/ostree/repo" remote add --no-gpg-verify generate-remote http://127.0.0.1:$PORT $BRANCHNAME
ostree --repo="$OSTREE_SYSROOT/ostree/repo" remote add --no-gpg-verify generate-remote "http://127.0.0.1:$PORT" $BRANCHNAME
ostree --repo="$OSTREE_SYSROOT/ostree/repo" pull generate-remote $BRANCHNAME
)

Expand Down
4 changes: 2 additions & 2 deletions tests/run_vector_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ TTV_DIR="$TESTS_SRC_DIR/tuf-test-vectors"
python -m pip install wheel
python -m pip install -r "$TTV_DIR/requirements.txt"

PORT=$("$TESTS_SRC_DIR/get_open_port.py")
ECU_SERIAL=test_primary_ecu_serial
HARDWARE_ID=test_primary_hardware_id

"$TTV_DIR/generator.py" --signature-encoding base64 -o vectors --cjson json-subset \
--ecu-identifier $ECU_SERIAL --hardware-id $HARDWARE_ID
# disable werkzeug debug pin which causes issues on Jenkins
WERKZEUG_DEBUG_PIN=off "$TTV_DIR/server.py" --signature-encoding base64 -P "$PORT" \
WERKZEUG_DEBUG_PIN=off "$TTV_DIR/server.py" --signature-encoding base64 -P 0 \
--ecu-identifier $ECU_SERIAL --hardware-id $HARDWARE_ID &
PORT=$("$TESTS_SRC_DIR/find_listening_port.sh" $!)
trap 'kill %1' EXIT

# wait for server to go up
Expand Down

0 comments on commit 720cb70

Please sign in to comment.