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: race condition in keploy record #1867

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Conversation

dxtym
Copy link

@dxtym dxtym commented May 7, 2024

Related Issue

  • Race condition with testCount while exiting keploy record

Closes: #1851

Describe the changes you've made

Put sync.Mutex locks over the sharing value so that concurrent activities don't cause race condition. Add sync.waitGroup to control the flow of actions between the main and sub gorountines.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, local variables)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Please let us know if any test cases are added

No additional tests. Only the build procedure at #1851

Describe if there is any unusual behaviour of your code(Write NA if there isn't)

NA

Checklist:

  • My code follows the style guidelines of this project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.

Screenshots (if any)

Original Updated
image image

Copy link

github-actions bot commented May 7, 2024

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thank you and congratulations 🎉 for opening your very first pull request in keploy

@dxtym
Copy link
Author

dxtym commented May 7, 2024

Singed-off-by: Dilmurod Abdusamadov [email protected]

@dxtym
Copy link
Author

dxtym commented May 7, 2024

I have read the CLA Document and I hereby sign the CLA

slayerjain added a commit that referenced this pull request May 7, 2024
@nehagup nehagup requested a review from slayerjain May 9, 2024 13:56
Copy link
Member

@slayerjain slayerjain left a comment

Choose a reason for hiding this comment

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

Hi @dxtym , Thanks for the PR! I have left some comments and I think @gouravkrosx / @charankamarapu should give more context for a better solution.

var mockCountMap = make(map[string]int)

// defering the stop function to stop keploy in case of any error in record or in case of context cancellation
defer func() {
select {
case <-ctx.Done():
waitGroup.Wait()
mutex.Lock()
r.telemetry.RecordedTestSuite(newTestSetID, testCount, mockCountMap)
Copy link
Member

Choose a reason for hiding this comment

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

I might be missing something but not really sure if this defer could be called concurrently 🤔

Copy link
Member

Choose a reason for hiding this comment

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

aah, so its the testCount probably..

Copy link
Member

Choose a reason for hiding this comment

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

I think in the defer function if we wait for the other goroutines to complete/cancel - this race condition can be better resolved. Maybe we can move the runAppErrGrp.Wait() in the defer to the top.

@charankamarapu @gouravkrosx what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

@dxtym , we can move the r.telemetry.RecordedTestSuite(newTestSetID, testCount, mockCountMap) to the bottom of the defer, this way we are waiting for all the go routines to complete their execution.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the comments @slayerjain @gouravkrosx! I moved the r.telemetry.RecordedTestSuite(newTestSetID, testCount, mockCountMap) to the bottom and removed mutex and waitGroups. Did I get your feedback right?

Copy link
Member

Choose a reason for hiding this comment

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

@dxtym yes, I think you've made the changes according to the feedback.

It seems like ctx cancellation is not working correctly based on the this pipeline - https://github.com/keploy/keploy/actions/runs/9034964803/job/24829105617?pr=1867

It seems to be stuck on the last line:

Screenshot 2024-05-10 at 9 55 22 PM

Copy link
Author

@dxtym dxtym May 12, 2024

Choose a reason for hiding this comment

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

I tried removing waitGroup from my previous solution, and the binary worked the same way. Perhaps we could try that

charankamarapu and others added 11 commits May 13, 2024 23:02
* [Feature]: Create a normalisation command in keploy CLI (keploy#1589)

* Initialised Normalise Command

Signed-off-by: Akash <[email protected]>

* Path init

Signed-off-by: Akash <[email protected]>

* Successfully found the expected and actual responses for failing tests

Signed-off-by: Akash <[email protected]>

* Files are being updated but structs are not proper: func WriteTestcase doesnt match yaml file

Signed-off-by: Akash <[email protected]>

* Updating testcase files successfully

Signed-off-by: Akash <[email protected]>

* Added flags to collect test-set and test-cases from user

Signed-off-by: Akash <[email protected]>

* Fixed lint errors

Signed-off-by: Akash <[email protected]>

* Fixed lint errors

Signed-off-by: Akash <[email protected]>

* Refactored PR for Keploy v2 and fixed merge conflicts

Signed-off-by: Akash Singh <[email protected]>

* Normalise Test cases

Signed-off-by: Akash Singh <[email protected]>

* Addressed comments and refactored changes

Signed-off-by: Akash Singh <[email protected]>

* Fixed Lint

Signed-off-by: Akash Singh <[email protected]>

* Fixed Lint

Signed-off-by: Akash Singh <[email protected]>

* Refactoring and Adding Additional Flags

Signed-off-by: Akash Singh <[email protected]>

* Added Normalise to replay service

Signed-off-by: Akash Singh <[email protected]>

* Fixed lint

Signed-off-by: Akash Singh <[email protected]>

---------

Signed-off-by: Akash <[email protected]>
Signed-off-by: Akash Singh <[email protected]>
Co-authored-by: Animesh Pathak <[email protected]>

* feat: add normalization

Signed-off-by: charankamarapu <[email protected]>

* fix: bugs

Signed-off-by: charankamarapu <[email protected]>

* fix: bugs

Signed-off-by: charankamarapu <[email protected]>

* fix: bugs

Signed-off-by: charankamarapu <[email protected]>

* fix: resolve comments

Signed-off-by: charankamarapu <[email protected]>

---------

Signed-off-by: Akash <[email protected]>
Signed-off-by: Akash Singh <[email protected]>
Signed-off-by: charankamarapu <[email protected]>
Co-authored-by: Sky Singh <[email protected]>
Co-authored-by: Animesh Pathak <[email protected]>
Signed-off-by: dxtym <[email protected]>
* chore: add docker ip log and remove a switch

Signed-off-by: Shubham Jain <[email protected]>

* fix: check container ip before starting tests

Signed-off-by: Shubham Jain <[email protected]>

---------

Signed-off-by: Shubham Jain <[email protected]>
Signed-off-by: dxtym <[email protected]>
ougoung -> outgoing

Signed-off-by: Priyansh Agrawal <[email protected]>
Co-authored-by: Sarthak Shyngle <[email protected]>
Signed-off-by: dxtym <[email protected]>
* fix: folder permissions

Signed-off-by: charankamarapu <[email protected]>

* fix: folder permissions

Signed-off-by: charankamarapu <[email protected]>

* fix: unset umask

Signed-off-by: charankamarapu <[email protected]>

* doc: add comment

Signed-off-by: charankamarapu <[email protected]>

* doc: add comment

Signed-off-by: charankamarapu <[email protected]>

---------

Signed-off-by: charankamarapu <[email protected]>
Signed-off-by: dxtym <[email protected]>
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.

[bug]: race condition in keploy record
9 participants