-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow setting different responses per request #31 #102
Allow setting different responses per request #31 #102
Conversation
* Adding logic to have multiple responses for similar request * Changed imposters json and yaml schema to have array of response instead just response * Fixing tests according to changes * Adding TODOs
* Updating TODOs
* Modularizig code * Added logic for random responses if burst field is absent
* Changing implementation of random mode and burst mode selection
* Updating TODO
* Updating exisiting and adding new documentation portion as per the feature.
* Ignoring negative or 0 value in the burst mode. Using 1 value in that case.
* Fixing and maintaining name consistencey in the response_handler.go file
* Updating TODOs
* Adding unit tests for repeatable responses * Removing TODO file * Changing name of a function
* Fixing comments
* Fixing comments
* Fixing linting errors * Fixing edge case of having no responses available * Added test case for no response available, fixing tests
* Adding test for no response and minor fixes
- `RANDOM` and `BURST` are valid values | ||
- `RANDOM` is default if field is not provided or any other value is provided. | ||
2. `response` -> `burst` (applicable only in `BURST` mode, ignored in) | ||
- +ve integer are valid values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by +ve
? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, +ve means positive. I'll change it to be positive instead of +ve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @infinite-spectrum,
Thanks a lot for your ideas & code contributions. I'll need more time to test the new features and to do an exhaustive code review. However, after a quick review, I have two things to begin the discussion with:
- What do you think about moving the
responseMode
to the imposter's level or to make theresponse
field an object withmode
andpayloads
fields within? - Have you tested your implementation with concurrent requests? I might be wrong (as I said I had no time to do some tests neither look at it in-detail), but looks like you're increasing the requests counter with no protection against concurrent requests (ergo potential data races).
Any thoughts about both topics? Thanks!! 😊
>> I'd go with 2nd option rather than the 1st one.
>> Nope, this is a miss from my end. I'll incorporate this one. |
I'm still wondering about how big that change is. In comparison with tools like Mountebank, in Killgrave is much simpler to define your imposters, so with this kind of change (forcing the user to define an array, etc) we're losing the added value that Killgrave brings into the ecosystem. That being said, do you think it could work to either:
What do you think? cc/ @aperezg
No worries at all, that's why code reviews are for. Feel free to ping me if you have any question related with that. Again, thanks a lot for your engagement with the project and your valuable contributions 🙏🏻 |
Using mutex lock for response handler's state change
@@ -54,14 +59,20 @@ func (rh *ResponseHandler) fillDefaults(imposter *Imposter) { | |||
rh.counter = 1 | |||
rh.currentInd = 0 | |||
} | |||
|
|||
rh.mutex = new(sync.Mutex) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK, there's no need to make the rh.mutex
a pointer neither to initialize it since rh
is already a pointer to a ResponseHandler
. See this example from the Go Tour. Thanks!
hello @infinite-spectrum will you continue with this PR? seems very good contibution so I hope to see this finish :D |
Hadling concurrent requests for repeating responses
@aperezg, sorry for the late submission. I've fixed the code for concurrent requests. Please review and let me know any suggestions/issues. |
@aperezg, we have to discuss one question - How to deal with the schema change? ( Here are few ideas:
Any other ideas would be appreciated. |
Hello @infinite-spectrum, sorry for the late response 🙏 so for continue with the PR, I think that the best idea would be that joan said, support the |
issue: #31
Following is the summary of the changes done in the PR so far:
burst
terminology for repeatable responses.Changed Items:
response
field in an imposter to responses (array of response)Added Items:
Added
burst
field in response schema under imposter schemaBURST
mode, ignored inRANDOM
modeBURST
mode if ignored/missing, the default value is 1Added
responseMode
field in request schema under imposter schemaRANDOM
orBURST
RANDOM
Input required:
responseMode
which is currentlyRANDOM