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

Execute custom code when a retry happens #188

Open
lobeu opened this issue Aug 9, 2023 · 2 comments
Open

Execute custom code when a retry happens #188

lobeu opened this issue Aug 9, 2023 · 2 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@lobeu
Copy link

lobeu commented Aug 9, 2023

Hi,

Im using XRetry and I would like to be alerted when a retry happens.

In my case I'd like to send a slack message to a certain channel, but another use case could be to attach a custom logger. Almost all the projects I worked on test automation had a custom logger.

So is there a way to execute some custom code when a retry happens?

Ive tried a lot to do this:

  • Making a fork and adding it to the RetryTestCaseRunner. But by doing this my test did not start anymore.
  • Trying to catch the DiagnosticMessage and doing something if a retry is logged, but I'm not able to read out the DiagnosticMessage and do something with it.

Is there a way to add something for this maybe?

@JoshKeegan
Copy link
Owner

JoshKeegan commented Aug 9, 2023

Hi,

is there a way to execute some custom code when a retry happens?

Not built-in. You'd need to either fork xRetry and add this, or enable diagnostic logs and then parsing them in a separate process to send alerts. I'd imagine parsing the logs in a separate process would be simpler than implementing it in a fork, and means you wouldn't have to worry about the additional code altering the way tests are run, e.g. by causing thread hopping.

Almost all the projects I worked on test automation had a custom logger

I think that would be beyond the scope of this project. Since xRetry is on top of xUnit, it just logs in the way xUnit makes available. If that were to ever be customisable it should be done via xUnit, or another plugin for it, rather than xRetry specifically offering a mechanism for a custom logger.

Trying to catch the DiagnosticMessage

I'm not sure what you mean by this as I don't know of anywhere it's exposed for a test to view.

@JoshKeegan JoshKeegan added enhancement New feature or request question Further information is requested labels Aug 9, 2023
@lobeu
Copy link
Author

lobeu commented Aug 10, 2023

Okay, thanks for the info, I'll try to parse the diagnostic logs then. That's what I meant by "catching the DiagnosticMessage" by the way.

With the custom logger, I meant that it would be a good use case for being able to execute some code if a retry happens. I would then just log "Retrying" to a text file. That way we can see if it happens on a Jenkins run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants