Repository navigation
TEST: Check the hardware lookup examples when the cloud fails or finds nothing - #235
Merged
Merged
Conversation
… TAC and native model examples When the cloud's accessible properties request failed as the pipeline was built, the examples ran the lookups. If processing then fetched the list for a key without the hardware lookup, they printed each heading with "No devices are associated" under it and exited with code 0, deciding from an empty lookup rather than from the list. Each example still checks the hardware engine's properties before any lookup. After processing a lookup, which fetches the accessible properties first when they are not known and throws the cloud service's error if that fails again, it checks them once more before using the result. So the decision is always made from a loaded list, a key without the lookup gets the one line and exit code 0, and a second failure ends with the cloud service's error and a non-zero exit code. The line is written by one method in each example. Two comments are corrected. TacCloud named a NativeModelLookup example, which is NativeModelCloud, and NativeModelCloud spelled pipeline wrongly.
…s nothing HardwareLookupWithoutProfilesTest becomes HardwareLookupStandInTest, whose stand-in for the cloud service answers what each test sets. Each case runs for both examples. - Without profiles. The accessible properties have no hardware element. The test now compares the whole line, and requires that nothing is logged as an error and no stack trace is printed, as well as exit code 0, no lookup heading and no lookup request. - No devices. The accessible properties carry the hardware element and each lookup answers with an empty list of profiles. Each heading must be followed by the line saying no devices are associated with the value. - Properties fail every time. The accessible properties request answers 500 with an error. The example must end with a non-zero exit code, with the cloud service's error logged as an error, no lookup heading, no line saying the key lacks the lookup and no lookup request. - Properties fail once. The first accessible properties request answers 500 and the next gives no hardware element. The example must ask again, print the line saying the key lacks the lookup with no heading, and end with exit code 0. The log lines carry colour codes around their level, which are removed before the output is checked. The two new fixtures come from answers the staging cloud gave, with the accessible properties cut down to what the examples use, and hold no key. AGENTS.md now names the error the examples end with against the published 4.5.130 packages, and says what the examples print when a lookup matches nothing or the property list cannot be fetched.
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.
Follows #234, which made the cloud TAC lookup example (TacCloud.java) and the cloud native model lookup example (NativeModelCloud.java) say in one line when the resource key does not include HardwarePlatform.Profiles, and made their live tests fail rather than pass when no device is listed.
Problem
Reviews of #234 found three gaps.
No devices are associated with this TAC.under it and exited with code 0. That is a decision made from an empty lookup rather than from the list.HardwareLookupWithoutProfilesTestchecked the exit code and the line, but would still pass if an error or a stack trace were logged on the way.AGENTS.md also said the examples "end with that error" against the published 4.5.130 packages without naming the error. Two old comments were wrong too. TacCloud pointed at a "NativeModelLookup" example, which is NativeModelCloud, and NativeModelCloud spelled pipeline wrongly.
What changed
The examples, in the first commit:
writeNoHardwareLookup, and the two comments are corrected.The tests, in the second commit, rename
HardwareLookupWithoutProfilesTesttoHardwareLookupStandInTest. Its stand-in for the cloud service on 127.0.0.1 answers the accessible properties, the evidence keys and the lookup with what each test sets, and anything else with 404. Each case runs for both examples, with a stand-in key and_51DEGREES_CLOUD_ENDPOINTpointing at the stand-in.hardwareelementhardwareelement, and each lookup with{"hardware":{"profiles":[]}}\tNo devices are associated with this TAC.or\tNo devices are associated with this native model name., no line saying the key lacks the lookup, one lookup request per value, nothing logged as an error and no stack tracehardwareelement, and the lookup with an answer that has nohardwareelementThe log lines carry colour codes around their level, so the test removes them before it looks for a line logged as an error. The two new fixtures,
accessibleproperties-with-hardware.jsonandjson-no-devices.json, come from answers the staging cloud gave, with the accessible properties cut down to what the examples use. Neither holds a key.AGENTS.md now says what the examples print when a lookup matches nothing and when the property list cannot be fetched. It also names what happens against the published 4.5.130 packages with a key without the lookup. The examples log
Aspect properties could not be loaded for fiftyone.devicedetection.cloud.flowelements.HardwareProfileCloudEngine, end withjava.lang.RuntimeException: Failed to load aspect properties for element 'hardware'and exit with code 1.The live tests,
TacCloudTestandNativeModelCloudTest, are unchanged. They are skipped whenKeyHelperfinds no usable key in_51DEGREES_RESOURCE_KEY_BESPOKE, which means the variable is not set or its value is not shaped like a resource key, as the other live tests in this repository are.How this was verified
Run in
examples/device-detectionwith JDK 21, offline, with thedevprofile and the libraries of rc installed from the root withmvnw install -Pdev -DskipTests -pl device-detection/device-detection.cloud,device-detection/device-detection -am. The library sources are unchanged since #234.mvnw -o -Pdev -pl console -am clean test -Dtest=HardwareLookupStandInTest,HardwareLookupOutputTest,CloudExamplesWithoutKeyTest,FindOutMoreCoverageTest,ConsoleConfigurationCoverageTest,CloudDropInTest#cloudResultsReadAsOnPremise,KeyHelperTest,FindOutMoreTest,ExampleProcessTest,PropertyHelperTest -DfailIfNoTests=false, with every variable holding a key removed-Dtest=HardwareLookupStandInTesttacCloudPropertiesFailOnceandnativeModelCloudPropertiesFailOnce, because those examples printed the headings with no devices instead of the linemvnw -o -Pdev -pl console -am clean test -Dtest=TacCloudTest,NativeModelCloudTest, with that key in_51DEGREES_RESOURCE_KEY_BESPOKEand_51DEGREES_CLOUD_ENDPOINTnaming the staging cloudApple iPhone 6 (A1586)andSamsung Galaxy S10 (SC-03L)_51DEGREES_RESOURCE_KEY_BESPOKE, productionThe resource key in _51DEGREES_RESOURCE_KEY_BESPOKE does not include HardwarePlatform.Profiles, which the TAC lookup needs.and... which the native model lookup needs.mvnw -o -pl console -am clean test-compilepwsh ci/check-environment-variable-names.ps1scripts/utm-lint.ps1 -RepoRoot . -Campaign 51degrees-javapwsh ci/check-root-locale.ps1What remains
_51DEGREES_RESOURCE_KEY_BESPOKEsecret is replaced with one that carries every CloudV5Bespoke property. The current key does not include HardwarePlatform.Profiles, soTacCloudTestandNativeModelCloudTestfail. That failure is intended, and it is already the case on rc since TEST: Check the cloud hardware lookup examples return devices #234.devprofile, which CI uses, or with the packages a publish has just built. The published 4.5.130 packages read the endpoint from another variable and cannot build the pipeline for a key without the hardware element, which Build a cloud engine whose product the resource key lacks, and log that once #84 and Give every environment variable one _51DEGREES_ name #105 changed on rc after 4.5.130.NullPointerExceptionrather than the status when the cloud answers a request with an error status and no body. The stand-in gives every error a body, as the cloud service does.The same behavior is being brought to the TAC and native model lookup examples and tests in the .NET, Python, Node.js, PHP and Rust repositories, so all six languages print and test these lookups in the same way.