Skip to content

Commit

Permalink
feat: filter out acceptance tests from validator usage report (#1683)
Browse files Browse the repository at this point in the history
  • Loading branch information
cka-y authored Mar 4, 2024
1 parent b36f2f7 commit 50eb0f5
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ public class Arguments {
description = "Export notices schema")
private boolean exportNoticeSchema = false;

@Parameter(
names = {"-svu", "--skip_validator_update"},
description = "Skips check for new validator version")
private boolean skipValidatorUpdate = false;

ValidationRunnerConfig toConfig() throws URISyntaxException {
ValidationRunnerConfig.Builder builder = ValidationRunnerConfig.builder();
if (input != null) {
Expand Down Expand Up @@ -135,6 +140,7 @@ ValidationRunnerConfig toConfig() throws URISyntaxException {
}
builder.setNumThreads(numThreads);
builder.setPrettyJson(pretty);
builder.setSkipValidatorUpdate(skipValidatorUpdate);
return builder.build();
}

Expand Down
31 changes: 16 additions & 15 deletions docs/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@
## via cli-app
**Full list of command line parameters available**

| Short name | Long name | required? | Description |
|------------|-------------------------------| ---------------------- |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `-i` | `--input` | Conditionally required | The path to the GTFS file (e.g., `/myDirectory/gtfs.zip`). Required if `-u` or `--url` is not provided. |
| `-u` | `--url` | Conditionally Required | `--url` or `-u`: the fully qualified URL to the GTFS file (e.g., `https://www.abc.com/gtfs.zip`). Required if `-i` or `--input` is not provided. |
| `-o` | `--output` | Required | Path to where the validation report will be stored (e.g., `output`) |
| `-s` | `--storage_directory` | Optional | Target path where to store the GTFS archive. Downloaded from network (if not provided, the ZIP will be stored in memory). |
| `-c` | `--country_code` | Optional | Country code of the feed, e.g., `nl`. It must be a two-letter country code (ISO 3166-1 alpha-2). (e.g., `ca`, `us`). It can be either lower or upper case (e.g. `FR` or `GP`). If the country code is provided, phone numbers will be validated based on it. |
| `-h` | `--help` | Optional | Print help menu. |
| `-t` | `--threads` | Optional | Number of threads to be used by Java to run the validator. |
| `-v` | `--validation_report_name` | Optional | Name of the validation report (including `.json` extension). |
| `-r` | `--html_report_name` | Optional | Name of the HTML validation report (including `.html` extension). |
| `-e` | `--system_errors_report_name` | Optional | Name of the system errors report (including `.json` extension). |
| `-n` | `--export_notices_schema` | Optional | Export notice schema as a json file. |
| `-p` | `--pretty` | Optional | Pretty JSON validation report. If specified, the JSON validation report will be printed using JSON Pretty print. This does not impact data parsing. |
| `-d` | `--date` | Optional | The date used to validate the feed for time-based rules, e.g feed_expiration_30_days, in ISO_LOCAL_DATE format like '2001-01-30'. By default, the current date is used. |
| Short name | Long name | required? | Description |
|------------|-------------------------------| ---------------------- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `-i` | `--input` | Conditionally required | The path to the GTFS file (e.g., `/myDirectory/gtfs.zip`). Required if `-u` or `--url` is not provided. |
| `-u` | `--url` | Conditionally Required | `--url` or `-u`: the fully qualified URL to the GTFS file (e.g., `https://www.abc.com/gtfs.zip`). Required if `-i` or `--input` is not provided. |
| `-o` | `--output` | Required | Path to where the validation report will be stored (e.g., `output`) |
| `-s` | `--storage_directory` | Optional | Target path where to store the GTFS archive. Downloaded from network (if not provided, the ZIP will be stored in memory). |
| `-c` | `--country_code` | Optional | Country code of the feed, e.g., `nl`. It must be a two-letter country code (ISO 3166-1 alpha-2). (e.g., `ca`, `us`). It can be either lower or upper case (e.g. `FR` or `GP`). If the country code is provided, phone numbers will be validated based on it. |
| `-h` | `--help` | Optional | Print help menu. |
| `-t` | `--threads` | Optional | Number of threads to be used by Java to run the validator. |
| `-v` | `--validation_report_name` | Optional | Name of the validation report (including `.json` extension). |
| `-r` | `--html_report_name` | Optional | Name of the HTML validation report (including `.html` extension). |
| `-e` | `--system_errors_report_name` | Optional | Name of the system errors report (including `.json` extension). |
| `-n` | `--export_notices_schema` | Optional | Export notice schema as a json file. |
| `-p` | `--pretty` | Optional | Pretty JSON validation report. If specified, the JSON validation report will be printed using JSON Pretty print. This does not impact data parsing. |
| `-d` | `--date` | Optional | The date used to validate the feed for time-based rules, e.g feed_expiration_30_days, in ISO_LOCAL_DATE format like '2001-01-30'. By default, the current date is used. |
| `-svu` | `--skip_validator_update` | Optional | Skip GTFS version validation update check. If specified, the GTFS version validation will be skipped. By default, the GTFS version validation will be performed. |

⚠️ Note that exactly one of the following options must be provided: `--url` or `--input`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ public ValidationRunner(VersionResolver versionResolver) {
}

public Status run(ValidationRunnerConfig config) {
VersionInfo versionInfo = versionResolver.getVersionInfoWithTimeout(Duration.ofSeconds(5));
VersionInfo versionInfo =
versionResolver.getVersionInfoWithTimeout(
Duration.ofSeconds(5), config.skipValidatorUpdate());
logger.atInfo().log("VersionInfo: %s", versionInfo);
if (versionInfo.updateAvailable()) {
logger.atInfo().log("A new version of the validator is available!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public Path systemErrorsReportPath() {
// If true, any output json will be pretty-printed.
public abstract boolean prettyJson();

// If true, the validator will not check for a new validator version
public abstract boolean skipValidatorUpdate();

public static Builder builder() {
// Set reasonable defaults where appropriate.
return new AutoValue_ValidationRunnerConfig.Builder()
Expand All @@ -72,7 +75,8 @@ public static Builder builder() {
.setNumThreads(1)
.setPrettyJson(false)
.setCountryCode(CountryCode.forStringOrUnknown(CountryCode.ZZ))
.setDateForValidation(LocalDate.now());
.setDateForValidation(LocalDate.now())
.setSkipValidatorUpdate(false);
}

@AutoValue.Builder
Expand All @@ -97,6 +101,8 @@ public abstract static class Builder {

public abstract Builder setPrettyJson(boolean prettyJson);

public abstract Builder setSkipValidatorUpdate(boolean skipValidatorUpdate);

public abstract ValidationRunnerConfig build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public VersionResolver(ApplicationType applicationType) {
* Attempts to resolve the application {@link VersionInfo} within the specified timeout. If the
* version info can't be resolved in the specified timeout, an empty info will be returned.
*/
public VersionInfo getVersionInfoWithTimeout(Duration timeout) {
public VersionInfo getVersionInfoWithTimeout(Duration timeout, boolean skipValidatorUpdate) {
try {
resolve();
resolve(skipValidatorUpdate);
return resolvedVersionInfo.get(timeout.toMillis(), TimeUnit.MILLISECONDS);
} catch (Throwable ex) {
return VersionInfo.empty();
Expand All @@ -65,7 +65,7 @@ public VersionInfo getVersionInfoWithTimeout(Duration timeout) {
* becomes available.
*/
public void addCallback(Consumer<VersionInfo> callback) {
resolve();
resolve(false);
Futures.addCallback(
resolvedVersionInfo,
new FutureCallback<>() {
Expand All @@ -83,7 +83,7 @@ public void onFailure(Throwable t) {
}

/** Starts version resolution on a background thread. */
public synchronized void resolve() {
public synchronized void resolve(boolean skipValidatorUpdate) {
if (resolutionStarted) {
return;
}
Expand All @@ -93,7 +93,10 @@ public synchronized void resolve() {
() -> {
try {
Optional<String> currentVersion = resolveCurrentVersion();
Optional<String> latestReleaseVersion = resolveLatestReleaseVersion(currentVersion);
Optional<String> latestReleaseVersion = Optional.empty();
if (!skipValidatorUpdate) {
latestReleaseVersion = resolveLatestReleaseVersion(currentVersion);
}
VersionInfo info = VersionInfo.create(currentVersion, latestReleaseVersion);
resolvedVersionInfo.set(info);
return info;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void testResolveLatestReleaseVersion() throws IOException {
mockStreamHandler.setContent("{\"version\":\"10.0.5\"}");

VersionResolver checker = new VersionResolver(ApplicationType.CLI);
VersionInfo versionInfo = checker.getVersionInfoWithTimeout(TIMEOUT);
VersionInfo versionInfo = checker.getVersionInfoWithTimeout(TIMEOUT, false);

assertThat(versionInfo.latestReleaseVersion()).hasValue("10.0.5");
}
Expand All @@ -53,7 +53,7 @@ public void testLatestReleaseVersionNotFound() throws IOException {
mockStreamHandler.setContent("Page not found");

VersionResolver checker = new VersionResolver(ApplicationType.CLI);
VersionInfo versionInfo = checker.getVersionInfoWithTimeout(TIMEOUT);
VersionInfo versionInfo = checker.getVersionInfoWithTimeout(TIMEOUT, false);

assertThat(versionInfo.latestReleaseVersion()).isEmpty();
}
Expand All @@ -67,7 +67,7 @@ public void testReleaseVersionUrlParams() throws IOException {
mockStreamHandler.setContent("{\"version\":\"10.0.5\"}");

VersionResolver checker = new VersionResolver(ApplicationType.WEB);
VersionInfo versionInfo = checker.getVersionInfoWithTimeout(TIMEOUT);
VersionInfo versionInfo = checker.getVersionInfoWithTimeout(TIMEOUT, false);

assertThat(mockStreamHandler.url).isNotNull();
assertThat(mockStreamHandler.url.getQuery())
Expand All @@ -81,7 +81,7 @@ public void testLocalVersion() {
assertThat(expectedVersion).isNotEmpty();

VersionResolver checker = new VersionResolver(ApplicationType.CLI);
VersionInfo versionInfo = checker.getVersionInfoWithTimeout(TIMEOUT);
VersionInfo versionInfo = checker.getVersionInfoWithTimeout(TIMEOUT, false);

assertThat(versionInfo.currentVersion()).hasValue(expectedVersion);
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/queue_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ do
ID=$(jq '.id' <<< "$item")
URL=$(jq '.url' <<< "$item")
path_name=${ID//\"/}
java -Xmx10G -Xms8G -jar gtfs-validator-snapshot/gtfs-validator*.jar --url $URL --output_base $OUTPUT_BASE/output/$path_name --validation_report_name latest.json --system_errors_report_name latest_errors.json
java -Xmx10G -Xms8G -jar gtfs-validator-snapshot/gtfs-validator*.jar --url $URL --output_base $OUTPUT_BASE/output/$path_name --validation_report_name latest.json --system_errors_report_name latest_errors.json --skip_validator_update
if [ "$master" = "--include-master" ];
then
java -Xmx10G -Xms8G -jar gtfs-validator-master/gtfs-validator*.jar --url $URL --output_base $OUTPUT_BASE/output/$path_name --validation_report_name reference.json --system_errors_report_name reference_errors.json
Expand Down

0 comments on commit 50eb0f5

Please sign in to comment.