Skip to content
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

fix: request count race condition #35

Closed
wants to merge 2 commits into from

Conversation

jonas-bleyl-form3
Copy link

When handling simultaneous requests that affect the same interaction we get a race condition for the request count when applying any modifiers. This is because we increment and retrieve the request count for an interaction in different steps without a lock.

This PR fixes this issue by not relying on the request count that could have been modified by another request.

@jonas-bleyl-form3 jonas-bleyl-form3 marked this pull request as ready for review December 23, 2022 09:37
Copy link
Contributor

@sofib-form3 sofib-form3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add tests that would cover the problem?
Ideally they would fail without changes and run happily with. 🙏

@jonas-bleyl-form3
Copy link
Author

@sofib-form3 Done. The test fails without the fix as expected. I did have to make a change to the concurrent requests tests as they weren't actually running the requests concurrently.

for _, res := range s.userResponses {
s.assert.Equal(res.StatusCode, s.modifiedNameStatusCode, "expected user status code")
for i, res := range s.userResponses {
if s.modifiedNameAttempt == nil || *s.modifiedNameAttempt == i+1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modifying attempt and number of concurrent requests have different results here - runs are concurrent so it may be out of order, perhaps the test would be more valuable if window of opportunity to fail was greater like using another fixture in test for example 10 requests per second and modify on attempt 4, or 7.

you'd need to figure a way to identify request with response in another way though

@andrea-f3
Copy link
Contributor

closed as duplicate of #46

@andrea-f3 andrea-f3 closed this Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants