Skip to content

Integration tests #6705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: dev-2.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Integration test

on:
pull_request:
types:
- labeled
- synchronize
env:
MAVEN_ARGS: "--no-transfer-progress -Dstyle.color=always"

jobs:
run:
runs-on: ubuntu-latest
if: github.repository_owner == 'opentripplanner' && contains( github.event.pull_request.labels.*.name, 'Integration Test' )
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin
cache: maven


- name: Run integration tests
run: mvn test-compile failsafe:integration-test -PprettierSkip
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
<module>gtfs-realtime-protobuf</module>
<module>application</module>
<module>otp-shaded</module>
<module>test/integration</module>
</modules>


Expand Down
11 changes: 10 additions & 1 deletion renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"org.mockito:mockito-core",
"com.tngtech.archunit:archunit",
"org.apache.maven.plugins:maven-surefire-plugin",
"org.apache.maven.plugins:maven-failsafe-plugin ",
"me.fabriciorby:maven-surefire-junit5-tree-reporter",
"com.google.truth:truth",
"org.jacoco:jacoco-maven-plugin", // coverage plugin
Expand Down Expand Up @@ -163,12 +164,20 @@
"description": "give some projects time to publish a changelog before opening the PR",
"matchPackageNames": [
"com.google.dagger:{/,}**",
"org.apache.httpcomponents.client5:httpclient5"
],
"matchUpdateTypes": ["major", "minor"],
"minimumReleaseAge": "1 week",
"schedule": "on the 13th through 14th day of the month"
},
{
"description": "Apache HTTP client",
"matchPackageNames": [
"org.apache.httpcomponents.client5:httpclient5"
],
"minimumReleaseAge": "1 week",
"changelogUrl": "https://github.com/apache/httpcomponents-client/blob/master/RELEASE_NOTES.txt",
"addLabels": ["Integration Test"]
},
{
"groupName": "Jackson non-patch",
"matchPackageNames": [
Expand Down
82 changes: 82 additions & 0 deletions test/integration/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.opentripplanner</groupId>
<artifactId>otp-root</artifactId>
<version>2.8.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>integration-test</artifactId>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>application</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.5.3</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
<consoleOutputReporter>
<disable>true</disable>
</consoleOutputReporter>
<reportFormat>plain</reportFormat>
<statelessTestsetInfoReporter
implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporter">
<printStacktraceOnError>true</printStacktraceOnError>
<printStacktraceOnFailure>true</printStacktraceOnFailure>
<printStdoutOnError>true</printStdoutOnError>
<printStdoutOnFailure>true</printStdoutOnFailure>
<printStdoutOnSuccess>false</printStdoutOnSuccess>
<printStderrOnError>true</printStderrOnError>
<printStderrOnFailure>true</printStderrOnFailure>
<printStderrOnSuccess>false</printStderrOnSuccess>
<theme>UNICODE</theme>
</statelessTestsetInfoReporter>
</configuration>
<dependencies>
<dependency>
<groupId>me.fabriciorby</groupId>
<artifactId>maven-surefire-junit5-tree-reporter</artifactId>
<version>1.4.0</version>
</dependency>
</dependencies>

</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.opentripplanner;

import static org.junit.jupiter.api.Assertions.assertNotEquals;

import jakarta.ws.rs.core.UriBuilder;
import java.io.IOException;
import java.time.Duration;
import java.util.Map;
import org.apache.commons.io.IOUtils;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.opentripplanner.framework.io.OtpHttpClient;
import org.opentripplanner.framework.io.OtpHttpClientFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* This integration test makes sure that Apache HTTP client still works with important hosts and
* HTTP servers.
*/
class OtpHttpClientTest {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @t2gran suggested the postfix for integration tests could be IntegrationTest.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use the (admittedly pretty dusty) integration test feature of maven (via the failsafe plugin) or use the tags to select just these tests, like we do with @GeneratesDocumentation. Do you have an opinion?


private static final Logger LOG = LoggerFactory.getLogger(OtpHttpClientTest.class);
private static final OtpHttpClient OTP_HTTP_CLIENT = new OtpHttpClientFactory().create(LOG);

@ParameterizedTest
@ValueSource(
strings = {
// a few entur URLs
"https://api.entur.io/mobility/v2/gbfs/",
"https://storage.googleapis.com/marduk-production/outbound/gtfs/rb_sjn-aggregated-gtfs.zip",
// Apache HTTP Client broke handling of S3 SSL certificates previously
"https://s3.amazonaws.com/kcm-alerts-realtime-prod/tripupdates.pb",
}
)
void httpGetRequest(String url) throws IOException {
var uri = UriBuilder.fromUri(url).build();

var stream = OTP_HTTP_CLIENT.getAsInputStream(uri, Duration.ofSeconds(30), Map.of());
var bytes = IOUtils.toByteArray(stream);

assertNotEquals(0, bytes.length, "Empty response body for %s".formatted(url));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the symptom of a HTTP client problem always an empty body?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the examples used in this test, yes.

I'm mainly testing that general HTTP calls don't throw an exception, which they did for two previous version upgrades.

}
}
Loading