Repository navigation
TEST: Expect the cloud address the environment gives in engine tests - #229
Merged
Merged
Conversation
The cloud request engine takes its address from code or configuration first, then the _51DEGREES_CLOUD_ENDPOINT environment variable, then https://cloud.51degrees.com/api/v4/ when both are blank. CI sets the variable to another service, so Process, Process_LicenseKey and OriginHeader in CloudRequestEngineTests failed because they expected the default address. ExpectedEndpoint works out the address a test that gives none should expect, the variable when it is set and not empty and the default otherwise, and CloudRequestEngineTestsBase builds expectedUrl from it. CloudRequestEngineBuilderTests gains three tests. An empty variable gives the default, the engine built in the real environment uses the address ExpectedEndpoint gives, and an address given in configuration is used for every request whatever the variable holds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The release pull request #190 (
rcintomain) fails on every runner in Release Pull Request run 45130693280. Three tests inCloudRequestEngineTestserror withThe method 'toString' should not have been called.:Each test checks that the data request went to
expectedUrl, whichCloudRequestEngineTestsBase.javaline 49 fixed athttps://cloud.51degrees.com/api/v4/resource_key.json. CI sets_51DEGREES_CLOUD_ENDPOINTto another service, so the engine correctly sent the request there, theargThatmatch failed, and Mockito calledtoStringon the strict mock while writing its failure message.The rule
The cloud request engine takes its address in this order.
setEndpoint) or in configuration (Endpoint)._51DEGREES_CLOUD_ENDPOINTenvironment variable.https://cloud.51degrees.com/api/v4/when both are blank.Every language reads the variable, so the whole suite can be run against a different service. The tests must follow the rule rather than give the engine the default address, which would stop the variable from being tested.
What was checked
CloudRequestEngineBuilder.javalines 98 to 106 apply the order above at build time, reading the variable through thegetEnvVarfunction at line 71, whichCloudRequestEngineBuilderTestsalready replaces by reflection to test the order.CloudRequestEngineBuilderTestsalready tests code over the variable (CloudEndPoint_Explicit_Setting), the variable over the default (CloudEndPoint_Environment_Setting) and the default when the variable is unset (CloudEndPoint_Default_Setting).What changed
Test code only, no change to the engine.
ExpectedEndpoint.java(new) works out the address a test that gives none should expect, in one place. That is the variable when it is set and not empty, otherwiseConstants.END_POINT_DEFAULT, ending in/as the builder makes it.CloudRequestEngineTestsBase.javabuildsexpectedUrlfromExpectedEndpoint.root(), which fixes the three failing tests.CloudRequestEngineBuilderTests.javagains three tests.CloudEndPoint_Blank_Environment_Setting: an empty variable gives the default.CloudEndPoint_Matches_Expected: an engine built in the real environment uses the addressExpectedEndpointgives.CloudEndPoint_Matches_Expected_For_Each_Variable: through thegetEnvVarhook, the engine andExpectedEndpoint.root(value)agree for a missing, empty, unslashed and slashed variable.CloudEndPoint_Configuration_Setting: the pipeline is given a builder whose variable is set through thegetEnvVarhook (withPipelineBuilder.addElementBuilder), and an address given in configuration (EndpointinPipelineOptions) is used for every request instead of the variable.How it was verified
On Windows with JDK 21 and the Maven wrapper.
_51DEGREES_CLOUD_ENDPOINTset to another cloud address,./mvnw -pl pipeline/pipeline.cloudrequestengine -am test -Dtest='CloudRequestEngineTests,CloudRequestEngineBuilderTests' -Dsurefire.failIfNoSpecifiedTests=falsegaveTests run: 55, Failures: 0, Errors: 0, Skipped: 0andBUILD SUCCESS.Tests run: 55, Failures: 0, Errors: 0, Skipped: 0andBUILD SUCCESS.pipeline.cloudrequestengine(./mvnw -o -pl pipeline/pipeline.cloudrequestengine -am test "-Dtest=fiftyone.pipeline.cloudrequestengine.**") ran withTests run: 170, Failures: 0, Errors: 0(166 before plus the four new ones), both with the variable unset and with it set to another cloud address without a trailing slash. Set to an address that does not resolve, onlyHttpDataSetInExceptionandCloudRequestEngineLiveTestsfail, because both call the real service at the variable's address. The Geo Location cloud tests gave 15 passed, and the cloud engine developer example tests gave 6 run, 3 skipped (EndpointTestsskips itself when the variable is set).ci/check-environment-variable-names.ps1passed.Not run here: the full CI matrix (JDK 8, 11 and 17, Linux and macOS). Locally,
ValueCloudTestsin the Device Detection and IP Intelligence cloud modules could not run because the data submodule was not checked out (Cannot find device-detection/20000 Evidence Records.yml), which is unrelated to the address.Outstanding
Notes for the engine, not changed here.
setEndpoint(CloudRequestEngineBuilder.javalines 227 to 230) adds/before storing the address, so a blank address given in code or configuration is stored as/, and the blank check at line 98 never sees it as blank. A blank address given in code or configuration therefore does not fall through to the variable or the default.setEndpoint(null)throws at line 227.setDataEndpoint,setPropertiesEndpointorsetEvidenceKeysEndpoint(lines 248, 262 and 276), withoutsetEndpoint, are replaced at build time when line 98 finds no root address and callssetEndpointwith the variable or the default (lines 101 and 104).Other failures in the same run, not fixed here.
MacOS_X64_Java_17stopped at IP Intelligence :: Translation because Maven could not download a plugin:Plugin org.apache.maven.plugins:maven-resources-plugin:3.3.1 or one of its dependencies could not be resolved: ... Could not transfer artifact org.apache.maven.plugins:maven-resources-plugin:pom:3.3.1 from/to central (https://repo.maven.apache.org/maven2): repo.maven.apache.org: nodename nor servname provided, or not known.