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

[feature request] Thread-safety for asserts and logging facilities #4

Closed
blastrock opened this issue May 22, 2016 · 11 comments
Closed

Comments

@blastrock
Copy link

Hi,

I would like to know if this framework supports tests that are multithreaded. To clarify, I am not talking about running multiple tests in parallel, but about running one single test that involves multiple threads doing assertions in parallel. I know that Catch and Boost.Test crash when we do that, but I didn't see anything in doctest's feature page nor in its roadmap about this. Is this supported? Will it be?

@viboes
Copy link

viboes commented May 22, 2016

If you are doing assertions in multiple threads this is almost the same as running several test in parallel, isn't it?
So the question is if Doctest is thread-safe.

One additional question. Do you have any pointers to related issues in CATCH or Boost.Test?

@onqtam
Copy link
Member

onqtam commented May 22, 2016

This will definitely be added to the roadmap. Currently there is no synchronization happening.

@blastrock
Copy link
Author

@viboes The feature to run the tests in parallel would require more work than that on doctest I think. But as you said, I'm just asking if doctest is threadsafe (and that's indeed a better way to put it).

About the related issue on catch, see here, I don't know if an issue is open on Boost.Test.

@onqtam Thanks!

@viboes
Copy link

viboes commented May 22, 2016

@blastrock if no one creates an issue to Boost.Test no fix could be expected ;-) The question is also if Boost.Test document that it is thread-safe.

@onqtam Adding synchronization always will make the test execution slower ("Don't pay for what you don't use"). It would be great if the tester could opt-in this feature and let most of the test continue to run as fast as possible.

@onqtam
Copy link
Member

onqtam commented May 22, 2016

@viboes yes - the default case will be without synchronization :)

But no guarantees when this will be done.

@viboes
Copy link

viboes commented May 22, 2016

@onqtam Making DocTest thread-safe will add additional dependencies or move to C++11. In addition it is not an easy task. I would suggest you to concentrate on a mono-threaded version. You can document that the user must avoid using the library on several threads and that it is up to them to do the synchronization between the different threads they are launching.

The fact that other unit test frameworks are not thread-safe is a symptom that it is not simple.

@dascandy
Copy link

I've written a few test frameworks and all of them are not thread safe. The basic problem is that as soon as you have threading, you have an undefined synchronicity in timing, meaning that the reproductivity of your test results goes out the window. IE, your unit tests will be bad and hard to fix.

Your tests should guarantee a single unique way of running; that's what a unit test is for quite literally, to ensure that you test that a given path works. If you have threading you should ensure that it does not interfere with the reliability of your tests, and that implicitly removes any use you can get out of this.

Running multiple tests in parallel I'm in favor, but I would feel that you're likely to hit slightly non-threadsafe code and you'll get unreproducible problems right back at you.

@blastrock
Copy link
Author

@dascandy In my case, I want to test a multithreading library. I know that I won't get reproducibility, but still, it's better to have tests that may fail when there is a bug than no tests at all. I guess that people that rely on these multithreading libraries may have the same constraints (that their code may run in parallel and in a non-deterministic way).

blastrock added a commit to blastrock/doctest that referenced this issue Feb 7, 2018
blastrock added a commit to blastrock/doctest that referenced this issue Feb 7, 2018
onqtam added a commit that referenced this issue Jul 11, 2018
…est case is now safe! using the SUBCASE macro in multiple threads will remain a big NO. TODO: logging macros such as INFO() and CAPTURE()... relates #4 and also PR #117 which was a good starting point for this!
@onqtam
Copy link
Member

onqtam commented Jul 11, 2018

I just pushed the thread safety support in commit 60e8a45 in the dev branch! asserts can now be safely used in multiple threads! what remains is the logging functionality...

thanks to @blastrock for showing me how simple this was (once I switched to C++11 for 2.0) in his PR!

I will not promise a release date however... but the work I have left for version 2.0 isn't much - all I have to do is implement an xml reporter with the new IReporter interface - but I should research xml encoding and other non-interesting things... :D (and document all new features...) so I hope that is... in the near month.

onqtam added a commit that referenced this issue Aug 17, 2018
…on - no need to allocate streams anymore - reusing a single one) - relates #4
onqtam added a commit that referenced this issue Aug 17, 2018
…thread local storage (__thread and __declspec(thread) respectively) but it works only for POD types... relates #4
@onqtam
Copy link
Member

onqtam commented Aug 17, 2018

logging functionality can now be used in a thread-safe manner as well - at the cost of dropping GCC 4.7 and VS 2013 from the list of supported compilers. not documented yet, and also no thread-sanitizer CI builds yet.

onqtam added a commit that referenced this issue Aug 17, 2018
…reporter for windows when attached to a VS debugger) - relates #4
onqtam added a commit that referenced this issue Aug 17, 2018
onqtam added a commit that referenced this issue Aug 17, 2018
onqtam added a commit that referenced this issue Aug 20, 2018
@onqtam onqtam changed the title Support for multi-threaded test? [feature request] Thread-safety for asserts and logging facilities Aug 20, 2018
onqtam added a commit that referenced this issue Aug 23, 2018
…est case is now safe! using the SUBCASE macro in multiple threads will remain a big NO. TODO: logging macros such as INFO() and CAPTURE()... relates #4 and also PR #117 which was a good starting point for this!
onqtam added a commit that referenced this issue Aug 23, 2018
…on - no need to allocate streams anymore - reusing a single one) - relates #4
onqtam added a commit that referenced this issue Aug 23, 2018
…thread local storage (__thread and __declspec(thread) respectively) but it works only for POD types... relates #4
onqtam added a commit that referenced this issue Aug 23, 2018
…reporter for windows when attached to a VS debugger) - relates #4
onqtam added a commit that referenced this issue Aug 23, 2018
onqtam added a commit that referenced this issue Aug 23, 2018
onqtam added a commit that referenced this issue Aug 23, 2018
@onqtam
Copy link
Member

onqtam commented Dec 6, 2018

Forgot to close this with the release of 2.0.0

@onqtam onqtam closed this as completed Dec 6, 2018
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

No branches or pull requests

4 participants