跨AppDomains实施引用计数的最佳方法是什么?(What would be the best way to implement reference counting across AppDoma

编程入门 行业动态 更新时间:2024-10-25 18:25:46
跨AppDomains实施引用计数的最佳方法是什么?(What would be the best way to implement reference counting across AppDomains?)

我觉得我可能会发生一些完全错误的事情,所以如果你有其他方法,请告诉我。

我正在使用服务堆栈构建服务。 我正在使用Xunit和NCrunch测试该服务。 我希望我的测试并行运行,他们目前要感谢NCrunch ...但是,有一个问题。

我的所有测试都依赖于我的服务启动并运行这一事实 - 它是一个共享资源......一个依赖项。 我并不特别关心它,但似乎服务堆栈不允许你为每个测试旋转多个实例(另外,我需要做一些令人讨厌的表前缀或postgresql里面的东西 - blek)...

我需要的是在任何测试运行之前通过代码启动我的服务的一些方法 - 并在所有测试完成后停止它。 我需要它是通过代码,因为如果我必须手动启动服务,我不会收到服务器端代码的代码覆盖率信息。

我可以手动启动服务,我的所有测试都是并行运行并且完全正常 - 但问题是我似乎找不到一个好的钩子来进行'预测试'和'后测试'动作。

我已经研究过使用信号量作为一种“引用计数”解决方案,但它实际上与我需要的相反。 我不想提前指定将运行多少测试..我需要类似于计数信号量的dijkstra - 但我没有找到一个基于命名(系统范围)信号量工作的实现。

Mutex不起作用 - 因为启动服务的测试仍然必须知道所有其他测试何时在停止服务之前完成 - 它不能在Dispose方法中这样做。

许多与线程之间的对象同步相关的正常解决方案在这种情况下不适用,因为测试是在自己的AppDomain中运行的。

在此先感谢您的所有帮助。

I feel like I may be going about something entirely wrong, so if you have an alternate approach, please let me know.

I'm building a service with service stack. I'm testing that service with Xunit and NCrunch. I want my tests to run in parallel, and they currently do thanks to NCrunch... However, there is one problem.

All of my tests rely on the fact that my service is up and running - it's a shared resource.. a dependency. I don't particularly care for it, but it seems that service stack does not let you spin up multiple instances for each test (plus, I'd need to do some nasty table prefixes or something inside postgresql - blek)...

All I need is some way to start my service via code before any tests have run - and stop it when all tests have finished. I need it to be via code because I don't receive code coverage information on server-side code if I have to start the service manually.

I can manually start the service and all my tests run in parallel and pass perfectly fine - but the problem is that I can't seem to find a good hook for a 'pre-test' and 'post-test' action.

I have looked into using a semaphore as a sort of 'reference counting' solution, but it's actually the opposite of what I'd need. I don't want to have to specify ahead of time how many tests will be ran.. I need something similar to a dijkstra counting semaphore - but I haven't found an implementation that works based upon a named (system-wide) semaphore.

A Mutex won't work - because the test that happens to start the service still has to know when all of the other tests finish before stopping the service - it cannot just do so in the Dispose method.

A lot of the normal solutions related to synchronizing objects between threads does not apply in this situation because the tests are ran inside their own AppDomain.

Thanks for all your help in advance.

最满意答案

几年前,我写了一篇关于解决类似问题的博客文章。

http://netvignettes.wordpress.com/2012/01/03/sharepoint-net-3-5-woes-and-synchronization-between-processes/

向下滚动到代码块并开始在那里阅读,这样您就可以跳过顶部的SharePoint cruft。

I wrote a blog post about a solution to a similar problem a couple of years ago.

http://netvignettes.wordpress.com/2012/01/03/sharepoint-net-3-5-woes-and-synchronization-between-processes/

Scroll down to the code blocks and start reading around there, so you can skip the SharePoint cruft at the top.

更多推荐

本文发布于:2023-04-28 03:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1329828.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法   AppDomains   implement   counting   reference

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!