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

【设计】并行运行大量测试用例时为什么使用多进程模式而非多线程 #7

Open
lymslive opened this issue Apr 9, 2024 · 0 comments
Labels
wontfix This will not be worked on

Comments

@lymslive
Copy link
Owner

lymslive commented Apr 9, 2024

这个 couttast 库的初衷是为了快速简单测试。只有当真正在一个测试程序编译了大量测试用例时,在默认全量自动化测试时需要花费可观时间才需要考虑并行加速的问题。

多线程虽然比多进程更便宜更快一丢丢,但它会限制用户写测试用例的简单自由度,用户写的测试用例代码要求注意多线程安全,比如不能访问全局变量,虽然这并不建议,但文件级静态变量还是很方便测试的。同时更重要的是,不能在自由函数中使用 COUT 断言宏,不能自由拆解很长的(可能也复杂或不复杂)测试用例,而只能用在库提供的宏定义测试用例内。

所以只在必要时用 fork 子进程的方式并行执行测试用例,可保证用例物理隔离互不影响。减轻用户写测试代码的心智负担,直接上手写,不必担心并行竞态问题。

但是在一个单元测试用例内,也可以测多线程的目标函数或库,或自己开启多线程,但出要注意自行在用例结束时 join 等待这些开启的多个线程。否则主线程从 main 可能会先退出,而在被测目标的线程内未完成预期任务。

@lymslive lymslive added the wontfix This will not be worked on label Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant