Skip to content

Commit

Permalink
fixup! test: fix tests so they'll run on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
apotterri committed Oct 10, 2023
1 parent 7cce2ad commit d3bdc84
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 42 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ jobs:

- name: Run Tests
shell: bash
run: bash --version && ./gradlew -i check integrationTest && bin/test
run: |
set -e
bin/disable-gradle-daemon
./gradlew -i check integrationTest
bin/test
4 changes: 2 additions & 2 deletions agent/bin/test_install
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function install_petclinic (
git checkout "${oldVersion}"
;;
esac
./mvnw --quiet package -Dmaven.test.skip=true
./mvnw --quiet package -DskipTests -Dcheckstyle.skip=true -Dspring-javaformat.skip=true
else
case "${JAVA_VERSION}" in
1.8*)
Expand All @@ -37,7 +37,7 @@ function install_petclinic (
echo "No old version, not packaging in ${pkg}"
;;
17.*)
./mvnw --quiet package -Dmaven.test.skip=true
./mvnw --quiet package -DskipTests -Dcheckstyle.skip=true -Dspring-javaformat.skip=true
;;
esac
fi
Expand Down
3 changes: 2 additions & 1 deletion agent/bin/test_run
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -e
# set -e

export PATH="$BATS_DIR"/bin:$PATH

Expand All @@ -13,6 +13,7 @@ report_failure() {

trap 'report_failure $LINENO' ERR

set -x
./test/petclinic/test
if [[ $JAVA_VERSION == 17.* ]]; then
./test/petclinic-fw/test
Expand Down
2 changes: 1 addition & 1 deletion agent/test/access/test
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

bats --tap test/access/access.bats
bats -x --tap test/access/access.bats
2 changes: 1 addition & 1 deletion agent/test/agent_cli/test
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cp test/petclinic/appmap.yml test/agent_cli/spring-petclinic/.
mkdir -p build/log

run_bats() {
bats --tap test/agent_cli/agent_cli.bats > build/log/bats-agent_cli.log 2>&1
bats -x --tap test/agent_cli/agent_cli.bats
}
${@:-run_bats}
bats_ret=$?
Expand Down
2 changes: 1 addition & 1 deletion agent/test/classloading/test
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
bats --tap test/classloading "${@}"
bats -x --tap test/classloading "${@}"
21 changes: 13 additions & 8 deletions agent/test/helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ start_recording() {
}

stop_recording() {
output="$(_curl -sXDELETE ${WS_URL}/_appmap/record | tee /dev/stderr)"
local out="${1:-$BATS_TEST_TMPDIR/stop_recording_output}"
_curl -sXDELETE -o "$out" "${WS_URL}/_appmap/record" || true
[ -f $out ] && output="$(< $out)" || true
}

teardown() {
Expand All @@ -26,7 +28,7 @@ print_debug() {
local query="${1}"
local result="${2}"

if [[ ! -z "${DEBUG_JSON}" ]]; then
if [[ ! -z "${DEBUG_JSON}" || ! -z "${JSON_DEBUG}" ]]; then
echo >&3
echo "query: ${query}" >&3
echo >&3
Expand Down Expand Up @@ -83,7 +85,7 @@ assert_json_not_contains() {
}

find_agent_jar() {
echo "$PWD/build/libs/$(ls build/libs | grep 'appmap-[[:digit:]]')"
echo "$(git rev-parse --show-toplevel)/agent/build/libs/$(ls build/libs | grep 'appmap-[[:digit:]]')"
}

check_ws_running() {
Expand Down Expand Up @@ -144,17 +146,17 @@ start_petclinic() {
}

start_petclinic_fw() {
export LOG_DIR=$PWD/build/log
WD="$(git rev-parse --show-toplevel)/agent"
export LOG_DIR="$WD/build/log"
mkdir -p ${LOG_DIR}

export LOG=$PWD/build/fixtures/spring-framework-petclinic/petclinic.log
export LOG="$WD/build/fixtures/spring-framework-petclinic/petclinic.log"
export WS_SCHEME="http" WS_HOST="localhost" WS_PORT="8080"
export WS_URL="${WS_SCHEME}://${WS_HOST}:${WS_PORT}"

check_ws_running

printf ' starting PetClinic (framework)\n'
WD=$PWD
AGENT_JAR="$(find_agent_jar)"

pushd build/fixtures/spring-framework-petclinic >/dev/null
Expand All @@ -164,10 +166,13 @@ start_petclinic_fw() {
local mvn_pid=$!
popd >/dev/null

while ! pgrep -P $mvn_pid; do
while ! ps -p $mvn_pid >/dev/null; do
sleep 1
done
export JVM_PID=$(pgrep -P $mvn_pid)
# Final check, this will fail if the server didn't start
ps -p $mvn_pid

export JVM_PID=$(ps -p $mvn_pid | awk 'END {print $1}')

wait_for_ws
}
Expand Down
4 changes: 2 additions & 2 deletions agent/test/http_client/test
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
bats --tap test/http_client "${@}"
#!/usr/bin/env bash
bats -x --tap test/http_client "${@}"
15 changes: 6 additions & 9 deletions agent/test/httpcore/httpcore.bats
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ load '../helper'
_curl -XGET "${WS_URL}"

stop_recording

echo "${output}" >&3
# Sanity check the events and classmap
assert_json_eq '.events | length' 6

Expand All @@ -80,14 +80,11 @@ load '../helper'

# Pick the functions out of the classMap
local filter='[.classMap | paths(objects) as $p | getpath($p) | select(.type == "function")]'

local join='join(",")'

assert_json_eq "${filter}[0].name" 'sayHello'
assert_json_eq "${filter}[0].labels" '[
"say",
"Hello"
]'
assert_json_eq "${filter}[0].labels | ${join}" 'say,Hello'

assert_json_eq "${filter}[1].name" 'handle'
assert_json_eq "${filter}[1].labels" '[
"handler"
]'
assert_json_eq "${filter}[1].labels | ${join}" 'handler'
}
2 changes: 1 addition & 1 deletion agent/test/httpcore/test
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ start_server() {
start_server

run_bats() {
bats --tap test/httpcore/httpcore.bats > build/log/bats-httpcore.log 2>&1
bats -x --tap test/httpcore/httpcore.bats
}
${@:-run_bats}
bats_ret=$?
Expand Down
2 changes: 1 addition & 1 deletion agent/test/jdbc/test
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
LOG=build/log/bats-jdbc.log
trap "cat $LOG" ERR

bats --tap test/jdbc/jdbc.bats >$LOG 2>&1
bats --x -tap test/jdbc/jdbc.bat
2 changes: 1 addition & 1 deletion agent/test/petclinic-fw/test
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
bats --tap test/petclinic-fw"${@}"
bats -x --tap test/petclinic-fw"${@}"
15 changes: 7 additions & 8 deletions agent/test/petclinic-shared/message-params.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ _test_form_data_is_recorded_as_message_parameters() {
run _curl -sf -o /dev/null "${WS_URL}/owners/1/edit" \
--data-raw 'firstName=Ben&lastName=Franklin&address=110+W.+Liberty+St.&city=Madison&telephone=6085551023'
assert_success
stop_recording
local out="$BATS_TEST_TMPDIR/stop_recording_output"
stop_recording "${out}"

local appmap="$(npx @appland/appmap prune --output-data /dev/stdin <<< "$output")"
run jq -r '.events[] | select(.http_server_request.normalized_path_info == "/owners/{ownerId}/edit") | .message[] | .name' <<< "${appmap}"
assert_output 'firstName
lastName
address
city
telephone'
run npx @appland/appmap@latest prune --output-data "${out}"
assert_success

run jq -r '[.events[] | select(.http_server_request.normalized_path_info == "/owners/{ownerId}/edit") | .message[] | .name] | join(",")' <<< "${output}"
assert_output 'firstName,lastName,address,city,telephone'
}

_test_the_agent_doesnt_exhaust_theInputStream() {
Expand Down
2 changes: 1 addition & 1 deletion agent/test/petclinic/test
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
bats --tap test/petclinic "${@}"
bats -x --tap test/petclinic "${@}"
2 changes: 1 addition & 1 deletion agent/test/spark/test
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
bats --tap test/spark "${@}"
bats -x --tap test/spark "${@}"
6 changes: 6 additions & 0 deletions bin/disable-gradle-daemon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -e

mkdir -p ~/.gradle
echo "org.gradle.daemon=false" >> ~/.gradle/gradle.properties
3 changes: 0 additions & 3 deletions bin/test
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/usr/bin/env bash

which bash
bash --version

set -e

(cd agent && bin/run_tests)

0 comments on commit d3bdc84

Please sign in to comment.