{{ message }}
Add retryable GET assertions and JSONPath-based expected response extraction#6266
Open
Add retryable GET assertions and JSONPath-based expected response extraction#6266
Conversation
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.

This PR improves
xtaskworkload command validation by adding retryable GET assertions and JSONPath-based response extraction forexpected_responsechecks. When working on #6193, The first implementation was much easier to test with those changes inxtasks. We changed direction later on but I think it can stil be useful for writing workloads tests.What changed
retryForfield to workload commands so GET requests can be retried for a bounded duration when the response does not yet match the expected payload$extractorsupport inexpectedResponseso workloads can assert against a JSONPath-selected subset of the server responsewhen
retryForis set and the command is aGET, we now wait for 500ms between new attempt. UsingretryForwith any method but aGETis just ignored and default to the existing behavior. Also,retryForwon't retry when the expected status doesn't match. It might sound counter-intuitive but the feature was initially added to retry when only the content of successful request didn't match. Nothing prevents us from retrying in that specific case though.As the spec demands, querying with
jsonpathalways returns an array. To improve the ergonomics, I inspect theexpectedValueproperty and promote any value to an array unless it's already an array of course. This feature is really useful when what you need to expect is nested deep into an object and using our placeholder syntax is not possible.Worth noting that the extractor feature doesn't work well with
--update-response. If you do use that flag, it will just overwrite theexpectedResponsewith the full response, not the extracted part. That means the extractor feature doesn't play nice withregistereither. I believe if you need the extraction feature, you shouldn't need--update-responseorregister.I tried to find an existing workload to "prove" that feature works but I didn't find any suitable candidate.
Command example
{ "route": "/indexes", "method": "GET", "retryFor": "10s", "expectedStatus": 200, "expectedResponse": { "$extractor": { "path": "$.results[*].uid", "expectedValue": ["movies"] } } }Generative AI tools