Skip to content

Commit

Permalink
feat: Expand and modularize the integration test suite
Browse files Browse the repository at this point in the history
Drop the Docker containers - we need the gradle and maven caches to get
reasonable build times. If we need to do a build matrix of Java VM
versions, we can use Travis to do that.

Refactor the single large bats file into separate test suites with their
own fixtures.
  • Loading branch information
kgilpin committed Jul 31, 2021
1 parent 397e200 commit ad06488
Show file tree
Hide file tree
Showing 27 changed files with 217 additions and 215 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ cache:
directories:
- '$HOME/.gradle/caches/'
- '$HOME/.gradle/wrapper/'
- '$HOME/.m2/'

script:
- ./gradlew -is check
- ./gradlew -is test
- ./gradlew -is integrationTest
- ./bin/test

Expand Down
38 changes: 3 additions & 35 deletions bin/test
Original file line number Diff line number Diff line change
@@ -1,38 +1,6 @@
#!/usr/bin/env bash
#
# run smoke tests
set -e

# see https://blog.travis-ci.com/docker-rate-limits
if [ ! -z "$DOCKERHUB_PASSWORD" ] && [ ! -z "$DOCKERHUB_USERNAME" ]; then
echo "$DOCKERHUB_PASSWORD" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
fi

JAVA_VERSION=$(java -version 2>&1 | head -1 | cut -d'"' -f2 | sed 's/^1\.//'| cut -d'.' -f1)

if [ $JAVA_VERSION -lt "9" ]; then
CONFIG=test/docker/java8/Dockerfile
else
CONFIG=test/docker/java11/Dockerfile
fi

docker build \
-t "petclinic:latest" \
-f test/docker/petclinic/Dockerfile \
.

IMAGE_NAME=appmap-test
IMAGE_TAG=latest

docker build \
-t "${IMAGE_NAME}:${IMAGE_TAG}" \
-f $CONFIG \
.

set -e

printf '\n=== begin tests ===\n'
exec docker run -i $(tty -s && echo '-t') \
-v $PWD/test/smoke.bats:/test/smoke.bats \
--rm \
"${IMAGE_NAME}:${IMAGE_TAG}" \
"${@:-/sbin/entrypoint}"
./bin/test_install
./bin/test_run
22 changes: 22 additions & 0 deletions bin/test_install
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

set -e

mkdir -p build/fixtures
cd build/fixtures
fixture_dir=$(pwd)

git clone --depth 1 https://github.com/spring-projects/spring-petclinic.git \
&& cd spring-petclinic \
&& ./mvnw package -Dmaven.test.skip=true

cd ../../..
mkdir -p build/bats
cd build/bats
bats_dir=$(pwd)

git clone --depth 1 https://github.com/bats-core/bats-core.git \
&& git clone --depth 1 https://github.com/bats-core/bats-support.git \
&& git clone --depth 1 https://github.com/bats-core/bats-assert.git \
&& cd bats-core \
&& ./install.sh "$bats_dir"
7 changes: 7 additions & 0 deletions bin/test_run
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

export PATH="bats_dir"/bin:$PATH

./test/petclinic/test
./test/http_client/test
./test/agent_cli/test
1 change: 1 addition & 0 deletions src/main/java/com/appland/appmap/output/v1/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ private Event setId(Integer id) {
* @return true if the event fields have been frozen. If so, it's too late to change
* event properties because it's probably already been serialized.
*/
@JSONField(serialize = false, deserialize = false)
public boolean isFrozen() {
return frozen;
}
Expand Down
1 change: 1 addition & 0 deletions test/agent_cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spring-petclinic
39 changes: 39 additions & 0 deletions test/agent_cli/agent_cli.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bats

load '../../build/bats/bats-support/load'
load '../../build/bats/bats-assert/load'
load '../helper'

appmap_jar=build/libs/$(ls build/libs | grep 'appmap-[[:digit:]]')

# bats captures stdout and stderr to the same variable ($output). We
# need to hide the informational message from the agent commands so
# json assertions don't get confused.
@test "appmap agent init packages" {
run bash -c "java -jar $appmap_jar -d test/agent_cli/sampleproj init 2>/dev/null"
assert_success

assert_json_contains '.configuration.contents' 'path: pkg1'
assert_json_contains '.configuration.contents' 'path: pkg2'
}

@test "appmap agent init empty project" {
run bash -c "java -jar $appmap_jar -d test/agent_cli/emptyproj init 2>/dev/null"
assert_success

assert_json_contains '.configuration.contents' 'path: com.mycorp.pkg'
}

@test "appmap agent status petclinic" {
run bash -c "java -jar $appmap_jar -d test/agent_cli/spring-petclinic status 2>/dev/null"
assert_success

assert_json_eq '.properties.config.app' 'spring-petclinic'
assert_json_eq '.properties.config.present' 'true'
assert_json_eq '.properties.config.valid' 'true'
assert_json_eq '.properties.frameworks[0].name' 'gradle'
assert_json_eq '.properties.frameworks[1].name' 'maven'

# TODO: Configure the agent in the spring-petclinic pom.xml and verify that it's
# reported present and valid by the agent status command.
}
1 change: 1 addition & 0 deletions test/agent_cli/sampleproj/src/main/java/pkg1/pkg1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// intentionally blank
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// intentionally blank
1 change: 1 addition & 0 deletions test/agent_cli/sampleproj/src/main/java/pkg2/pkg2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// intentionally blank
14 changes: 14 additions & 0 deletions test/agent_cli/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -x

cp -r build/fixtures/spring-petclinic test/agent_cli
cp test/petclinic/appmap.yml test/agent_cli/spring-petclinic

run_bats() {
bats --tap test/agent_cli/agent_cli.bats > build/log/bats-agent_cli.log 2>&1
}
${@:-run_bats}
bats_ret=$?

cat build/log/bats-agent_cli.log
exit $bats_ret
43 changes: 0 additions & 43 deletions test/docker/java11/Dockerfile

This file was deleted.

43 changes: 0 additions & 43 deletions test/docker/java8/Dockerfile

This file was deleted.

11 changes: 0 additions & 11 deletions test/docker/petclinic/Dockerfile

This file was deleted.

33 changes: 0 additions & 33 deletions test/entrypoint

This file was deleted.

2 changes: 2 additions & 0 deletions test/http_client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
appmap
classes
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package test;
package http_client;

import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpClientTest {



public static void main(String[] argv) throws IOException {

final String WS_URL = argv[0];

URL url;
Expand Down
3 changes: 3 additions & 0 deletions test/http_client/appmap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: HTTP client test
packages:
- path: http_client.HttpClientTest
32 changes: 32 additions & 0 deletions test/http_client/http_client.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bats

load '../../build/bats/bats-support/load'
load '../../build/bats/bats-assert/load'
load '../helper'

WS_URL=${WS_URL:-http://localhost:8080}
appmap_jar=build/libs/$(ls build/libs | grep 'appmap-[[:digit:]]')
mkdir -p appmap

@test "expected number of http client events captured" {
skip

# Exception in thread "main" java.lang.NoClassDefFoundError: java/sql/Time
# at com.appland.shade.com.alibaba.fastjson.util.TypeUtils.addBaseClassMappings(TypeUtils.java:1456)
# at com.appland.shade.com.alibaba.fastjson.util.TypeUtils.<clinit>(TypeUtils.java:119)
# at com.appland.shade.com.alibaba.fastjson.serializer.SerializeConfig.getObjectWriter(SerializeConfig.java:544)
# at com.appland.shade.com.alibaba.fastjson.serializer.SerializeConfig.getObjectWriter(SerializeConfig.java:436)
# at com.appland.shade.com.alibaba.fastjson.serializer.SerializeConfig.getObjectWriter(SerializeConfig.java:527)
# at com.appland.shade.com.alibaba.fastjson.serializer.SerializeConfig.getObjectWriter(SerializeConfig.java:436)
# at com.appland.shade.com.alibaba.fastjson.serializer.JSONSerializer.getObjectWriter(JSONSerializer.java:410)
# at com.appland.shade.com.alibaba.fastjson.serializer.JSONSerializer.write(JSONSerializer.java:282)
# at com.appland.shade.com.alibaba.fastjson.JSONWriter.writeObject(JSONWriter.java:61)
# at com.appland.shade.com.alibaba.fastjson.JSONWriter.writeValue(JSONWriter.java:48)
# at com.appland.appmap.record.AppMapSerializer.writeClassMap(AppMapSerializer.java:211)

java -Xbootclasspath/a:$appmap_jar -javaagent:$appmap_jar -Dappmap.debug -Dappmap.config.file=test/http_client/appmap.yml \
-Dappmap.output.directory=test/http_client/appmap -Dappmap.record=http_client.HttpClientTest.main -cp test/http_client/classes http_client.HttpClientTest ${WS_URL}
output=$(<appmap/*.appmap.json)
assert_json_eq '[.events[] | select(.http_client_request)] | length' 3
assert_json_eq '[.events[] | select(.http_client_response)] | length' 3
}
42 changes: 42 additions & 0 deletions test/http_client/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash

set -x

basedir=test/http_client
cd test/http_client

javac -d classes -g HttpClientTest.java

cd -

export WS_URL="http://localhost:8080"

PETCLINIC_LOG=build/log/http_client_petclinic.log
java -ea -jar build/fixtures/spring-petclinic/target/$(ls build/fixtures/spring-petclinic/target | grep 'spring-petclinic-[[:digit:]].*\.jar$') &> $PETCLINIC_LOG &
JVM_PID=$!

printf 'Starting spring-petclinic'
while [ -z "$(curl -I "${WS_URL}" | grep 'HTTP/1.1 200')" ]; do
if ! kill -0 "${JVM_PID}" 2> /dev/null; then
printf '. failed!\n\nprocess exited unexpectedly:\n'
cat $PETCLINIC_LOG
exit 1
fi

printf '.'
sleep 1
done
printf ' ok\n\n'

mkdir -p build/log
run_bats() {
bats --tap test/http_client/http_client.bats > build/log/bats-http_client.log 2>&1
}
${@:-run_bats}
bats_ret=$?

kill ${JVM_PID}
wait ${JVM_PID}
cat $PETCLINIC_LOG
cat build/log/bats-http_client.log
exit $bats_ret
1 change: 1 addition & 0 deletions test/petclinic/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
classes
Loading

0 comments on commit ad06488

Please sign in to comment.