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

Start on_stop not before on_start has finished #969

Closed
ThomasSteinbach opened this issue Feb 28, 2019 · 4 comments
Closed

Start on_stop not before on_start has finished #969

ThomasSteinbach opened this issue Feb 28, 2019 · 4 comments
Labels
hacktoberfest See https://hacktoberfest.digitalocean.com for more info

Comments

@ThomasSteinbach
Copy link

ThomasSteinbach commented Feb 28, 2019

Description of issue / feature request

Wait with running on_stop until on_start has finished. This is because on_stop could depend on variables / statuses set during on_start:

def on_start(self):
    self.myvar = runSomeRequest()

def on_stop(self):
    deleteSomething(self.myvar)

[Edit]

Same case for tasks. The on_stop method would maybe not cleanup resources from the currently running task:

@task
def test(self):
    item = randomString()
    r = self.client.post('...', data = item)
    self.myvar.items.append(item)

def on_stop(self):
    for item in items:
      self.client.delete('...%s' % item)
@cyberw cyberw added the hacktoberfest See https://hacktoberfest.digitalocean.com for more info label Oct 19, 2019
@cyberw
Copy link
Collaborator

cyberw commented Oct 19, 2019

I havent validated the behaviour you are seeing, but it definitely looks like a bug, or at least a feature we would want.

@heyman
Copy link
Member

heyman commented Oct 20, 2019

This is not supposed to happen within the same Locust I think. If it does happen I'd really like to see a minimal reproducible example.

It's definitely possible that on_stop could be run on Locust User B while the on_start is still executing in Locust User A. That is something that we can'tdo much about since it would requiring synchronization across distributed nodes.

@heyman
Copy link
Member

heyman commented Oct 20, 2019

Sorry, I realised what I wrote in the previous message is incorrect. For some reason I thought you meant that on_stop could run before on_start, but I can clearly see that's not what you wrote.

It's correct that with the current implementation we do not wait for on_start to finish when the test is stopped. Instead the Locusts' greenlets are immediately killed which could happen while on_start is still being executed if it's long running, or the test is stopped very quickly after it has been started. I think #1099 might be able to change this behaviour though.

@cyberw
Copy link
Collaborator

cyberw commented Oct 26, 2019

Yes, this is pretty much solved by #1099 . I added a test case to verify it, and will PR it later (it turns out on_start and on_stop are not tested anywhere...)

@heyman heyman closed this as completed Oct 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest See https://hacktoberfest.digitalocean.com for more info
Projects
None yet
Development

No branches or pull requests

3 participants