From 50eb0f5690a56251c536a29fcabda1dc4d8c4f02 Mon Sep 17 00:00:00 2001 From: cka-y <60586858+cka-y@users.noreply.github.com> Date: Mon, 4 Mar 2024 16:54:30 -0500 Subject: [PATCH] feat: filter out acceptance tests from validator usage report (#1683) --- .../gtfsvalidator/cli/Arguments.java | 6 ++++ docs/USAGE.md | 31 ++++++++++--------- .../runner/ValidationRunner.java | 4 ++- .../runner/ValidationRunnerConfig.java | 8 ++++- .../gtfsvalidator/util/VersionResolver.java | 13 +++++--- .../util/VersionResolverTest.java | 8 ++--- scripts/queue_runner.sh | 2 +- 7 files changed, 45 insertions(+), 27 deletions(-) diff --git a/cli/src/main/java/org/mobilitydata/gtfsvalidator/cli/Arguments.java b/cli/src/main/java/org/mobilitydata/gtfsvalidator/cli/Arguments.java index 9e614c82c4..77a135a0cd 100644 --- a/cli/src/main/java/org/mobilitydata/gtfsvalidator/cli/Arguments.java +++ b/cli/src/main/java/org/mobilitydata/gtfsvalidator/cli/Arguments.java @@ -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) { @@ -135,6 +140,7 @@ ValidationRunnerConfig toConfig() throws URISyntaxException { } builder.setNumThreads(numThreads); builder.setPrettyJson(pretty); + builder.setSkipValidatorUpdate(skipValidatorUpdate); return builder.build(); } diff --git a/docs/USAGE.md b/docs/USAGE.md index 2f03057019..a93a0bd08b 100644 --- a/docs/USAGE.md +++ b/docs/USAGE.md @@ -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`. diff --git a/main/src/main/java/org/mobilitydata/gtfsvalidator/runner/ValidationRunner.java b/main/src/main/java/org/mobilitydata/gtfsvalidator/runner/ValidationRunner.java index 4a07f61cfa..0d394ab369 100644 --- a/main/src/main/java/org/mobilitydata/gtfsvalidator/runner/ValidationRunner.java +++ b/main/src/main/java/org/mobilitydata/gtfsvalidator/runner/ValidationRunner.java @@ -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!"); diff --git a/main/src/main/java/org/mobilitydata/gtfsvalidator/runner/ValidationRunnerConfig.java b/main/src/main/java/org/mobilitydata/gtfsvalidator/runner/ValidationRunnerConfig.java index 9eea19bb65..804d6ab165 100644 --- a/main/src/main/java/org/mobilitydata/gtfsvalidator/runner/ValidationRunnerConfig.java +++ b/main/src/main/java/org/mobilitydata/gtfsvalidator/runner/ValidationRunnerConfig.java @@ -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() @@ -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 @@ -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(); } } diff --git a/main/src/main/java/org/mobilitydata/gtfsvalidator/util/VersionResolver.java b/main/src/main/java/org/mobilitydata/gtfsvalidator/util/VersionResolver.java index 1e33fd3d0a..7ee78fb025 100644 --- a/main/src/main/java/org/mobilitydata/gtfsvalidator/util/VersionResolver.java +++ b/main/src/main/java/org/mobilitydata/gtfsvalidator/util/VersionResolver.java @@ -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(); @@ -65,7 +65,7 @@ public VersionInfo getVersionInfoWithTimeout(Duration timeout) { * becomes available. */ public void addCallback(Consumer callback) { - resolve(); + resolve(false); Futures.addCallback( resolvedVersionInfo, new FutureCallback<>() { @@ -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; } @@ -93,7 +93,10 @@ public synchronized void resolve() { () -> { try { Optional currentVersion = resolveCurrentVersion(); - Optional latestReleaseVersion = resolveLatestReleaseVersion(currentVersion); + Optional latestReleaseVersion = Optional.empty(); + if (!skipValidatorUpdate) { + latestReleaseVersion = resolveLatestReleaseVersion(currentVersion); + } VersionInfo info = VersionInfo.create(currentVersion, latestReleaseVersion); resolvedVersionInfo.set(info); return info; diff --git a/main/src/test/java/org/mobilitydata/gtfsvalidator/util/VersionResolverTest.java b/main/src/test/java/org/mobilitydata/gtfsvalidator/util/VersionResolverTest.java index d1694379a3..ffbf4a6575 100644 --- a/main/src/test/java/org/mobilitydata/gtfsvalidator/util/VersionResolverTest.java +++ b/main/src/test/java/org/mobilitydata/gtfsvalidator/util/VersionResolverTest.java @@ -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"); } @@ -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(); } @@ -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()) @@ -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); } diff --git a/scripts/queue_runner.sh b/scripts/queue_runner.sh index 7d5b4f0725..db2b190d45 100644 --- a/scripts/queue_runner.sh +++ b/scripts/queue_runner.sh @@ -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