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

Speedup mocks start/stop #58

Closed
wants to merge 3 commits into from
Closed

Conversation

irr123
Copy link
Contributor

@irr123 irr123 commented Sep 2, 2020

Tests speed up from 10min+ to 30sec on proj with 30+ mocks with go1.15

@luza
Copy link
Contributor

luza commented Sep 2, 2020

You've patched 3 different pieces of code:

  • make mock launching parallel
  • pre-cancel context which being passed to Shutdown()
  • make these Shutdowns itself parallel

How much each of them give speed gain? Are all three really necessary?

runner/runner.go Outdated
@@ -148,6 +148,7 @@ func (r *Runner) executeTest(v models.TestInterface, client *http.Client) (*mode

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
_ = resp.Body.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have only one _ = resp.Body.Close() call here? If you sure that body needs to be closed despite the error, let's call Close() before the error check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, we can.

And yep, needs to close body despite ReadAll err, it may be err about too large body or something else

@irr123
Copy link
Contributor Author

irr123 commented Sep 2, 2020

How much each of them give speed gain? Are all three really necessary?

I checked how many impact it changes separately do and you right, concurrent start/stop is needless

@@ -39,7 +39,9 @@ func (m *ServiceMock) StartServer() error {
}

func (m *ServiceMock) ShutdownServer() {
m.server.Shutdown(context.TODO())
ctx, cancel := context.WithCancel(context.TODO())
Copy link
Contributor

Choose a reason for hiding this comment

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

This also looks a bit hacky. At least here should be a comment describing why we create a context and then immediately cancel it.

Did you manage to find out why we still have active connections to mock server? Was it caused by not closed body in runner.go?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was it caused by not closed body in runner.go

Nope, it's rare edge case, I found it when investigating where connection may leak, but dont find

This also looks a bit hacky

There are exists another way, we can add new method:

func (m *ServiceMock) ShutdownServerContext(ctx context.Context) error

and than reuse it in ShutdownServer, like in others libraries, which migrated to context

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added comment here and made another PR with ShutdownServerContext method (#59), both of this solutions ok for me, choose what you like best

@fetinin fetinin linked an issue Sep 2, 2020 that may be closed by this pull request
@irr123 irr123 mentioned this pull request Sep 3, 2020
@luza luza closed this Sep 3, 2020
@luza
Copy link
Contributor

luza commented Sep 3, 2020

Closing in favour of #59

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.

Slow mocks shutdown in Go 1.15
3 participants