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

tests: MockIRCServer methods should block by default #2065

Merged
merged 5 commits into from
May 16, 2021

Conversation

dgw
Copy link
Member

@dgw dgw commented May 12, 2021

Description

tl;dr: Threaded callables can cause race conditions during tests, but the MockIRCServer is in a perfect position to make sure they don't (and it now does so).

I had a very interesting time this past weekend, trying to write tests for #2063 that simply wouldn't work, no matter what I did, until eventually the idea came to me: "Try it with the plugin callable set to unthreaded." After that, and an IRC discussion wherein @Exirel reminded me that the bot.running_triggers property exists, those tests got written and merged.

Now this new feature inspired by the above process is ready to be "formally" proposed. I spent some time on the documentation for it, proved the concept by running the test suite on three local Python versions (2.7, 3.3, and 3.8), and am reasonably confident that this is ready for the "bikeshedding" or "nitpicking" stage—that is, developed enough as a concept that I won't need to rewrite the whole patch based on feedback. 😉

I elected to go with the simpler Boolean argument value for the overriding (blocking) argument on each method. Also proposed was a numeric value that would allow a test writer to specify the timeout for threading.Thread.join(), but that seems needlessly complex. I can't see a use for tests where a call would sometimes block and sometimes time out—such a test would be prone to intermittent failures, and thus not very useful for CI. 😁

Checklist

  • I have read CONTRIBUTING.md
  • I can and do license this contribution under the EFLv2
  • No issues are reported by make qa (runs make quality and make test)
  • I have tested the functionality of the things this change touches

Notes

Of course, if I've made any silly assumptions about things like never needing to set a timeout on threading.Thread.join() sometimes, that's what the PR discussion is for!

The versionadded directives are committed separately, so I can easily update them if for some reason this doesn't go into 7.1. Otherwise, I plan to squash them into the relevant code commits before merging.

`factories.BotFactory` had an outdated example (old method name).

`pytest_plugin.ircfactory` contained a syntax error (typo) in its example.

`mocks.MockIRCServer.channel_joined` had a spelling error (typo).
@dgw dgw added the Tests label May 12, 2021
@dgw dgw added this to the 7.1.0 milestone May 12, 2021
@dgw dgw requested a review from Exirel May 12, 2021 06:49
Copy link
Contributor

@Exirel Exirel left a comment

Choose a reason for hiding this comment

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

Ship it.

dgw added 4 commits May 12, 2021 13:47
With 30 new lines of code (of which only about half is actual code), a
solid 20 lines can be removed from the `isup` tests.

The long-term benefit is that there will be less boilerplate required
when writing tests for plugin callables that are threaded (which is the
default value if the `@plugin.thread` decorator doesn't override it).
@dgw dgw force-pushed the auto-join-threads-MockIRCServer branch from 1f8847a to 297b71b Compare May 12, 2021 18:49
@dgw dgw merged commit 6c142b1 into master May 16, 2021
@dgw dgw deleted the auto-join-threads-MockIRCServer branch May 16, 2021 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants