等待间歇性故障

发布于 2024-12-13 18:36:33 字数 1030 浏览 0 评论 0原文

我的团队有一堆 WatiN 测试套件,它们由我们的 TeamCity 服务器自动运行。我们最近将所有构建代理切换为 64 位,我还将 WatiN 测试切换为在 x64 模式下使用 NUnit。由于对 IE 浏览器的互操作调用失败或其他原因,Watin 总是给我们带来罕见的测试失败,但这种情况一直非常罕见。由于将所有内容都切换到 64 位,几乎每次运行我们的测试套件都会失败,并出现以下异常:

Test(s) failed. System.InvalidCastException : Specified cast is not valid.
    at SHDocVw.IWebBrowser2.get_HWND()
    at WatiN.Core.Native.InternetExplorer.IEBrowser.get_hWnd()
    at WatiN.Core.DomContainer.StartDialogWatcher()
    at WatiN.Core.IE.CreateNewIEAndGoToUri(Uri uri, IDialogHandler logonDialogHandler, Boolean createInNewProcess)
    ...

我发现了一个相关问题,其中WatiN 用户看到了相同的异常,但这是因为她正在尝试多线程。我们没有做任何这样的事情,事实上我们正在使用 WatiN 文档建议的正确的线程状态单元。我确实注意到这个问题中有人评论说这可能是因为 x86 与 x64 模式。

如何避免此错误导致我的测试经常失败?

如果只是切换回 32 位模式的问题,我可以处理,但我想确定是否没有更好的解决方案。谢谢。

更新:
在使用 64 位 NUnit 运行程序运行大约 5 次以上的测试套件后,除了一次出现同样的错误外,它们每次都失败。我们将它们切换回 32 位,此后已经成功运行了 10 多次。我想现在的临时修复是使用 32 位 NUnit 运行程序,尽管我仍在寻找发生这种情况的原因或允许我们切换回 x64 的解决方案。

My team has a bunch of WatiN test suites which run automatically by our TeamCity server. We recently switched all of our build agents to 64 bit and I also switched our WatiN tests to use NUnit in x64 mode. Watin has always given us infrequent test failures because of failed Interop calls to the IE browser or for other reasons but these have always been quite rare. Since switching everything to 64 bit, almost every run of any of our test suites fails with the following Exception:

Test(s) failed. System.InvalidCastException : Specified cast is not valid.
    at SHDocVw.IWebBrowser2.get_HWND()
    at WatiN.Core.Native.InternetExplorer.IEBrowser.get_hWnd()
    at WatiN.Core.DomContainer.StartDialogWatcher()
    at WatiN.Core.IE.CreateNewIEAndGoToUri(Uri uri, IDialogHandler logonDialogHandler, Boolean createInNewProcess)
    ...

I found a related question where a WatiN user is seeing the same exception but it is because she is attempting multi-threading. We are not doing any such thing, infact we are using the correct thread state apartment as suggested by the WatiN documentation. I did notice in the question though that someone had commented saying it might be because x86 vs. x64 mode.

How can I avoid this error causing my tests to frequently fail?

If it is simply a matter of switching back to 32 bit mode, I can handle that but I wanted to know for sure that there is no better solution. Thanks.

UPDATE:
After leaving the jobs as using 64 bit NUnit runner for about 5+ runs of the test suites, they failed every time except once with this same error. We switched them back to 32 bit and have had 10+ successful runs since. I guess the temporary fix for now is use a 32 bit NUnit runner although I am still looking for a reason this happens or a solution that would allows us to switch back to x64.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨与橙与城 2024-12-20 18:36:33

我在 x64 上使用 Watin,它给我带来了一些麻烦。我最近查看了 Watin 的源代码,发现 PInvoke 调用似乎有缺陷(只能在 32b 系统上正常工作)。如果执行某些方法,它们会覆盖内存的某些部分(因为 32b 是为 64b 结果保留的),从而产生奇怪的错误。

这只是一个示例:
WatiN-2.1.0.1196/source/src/Core/Native/Windows/Win32.cs

public static extern Int32 SendMessageTimeout(IntPtr hWnd, Int32 msg, Int32 wParam, Int32 lParam, Int32 fuFlags, Int32 uTimeout, ref Int32 lpdwResult);

VS 正确

public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint msg, UIntPtr wParam, IntPtr lParam, uint fuFlags, uint uTimeout, out IntPtr lResult);

完整更改检查 http:// Pastebin.com/KaVpM6wT
当然,它需要重建 Watin.Core dll,并且不提供任何保证。

I am using Watin on x64 and it caused me some troubles. I recently reviewed the source code of Watin and it seems the PInvoke calls are flawed (working only on 32b system correctly). If you execute certain methods they overwrite some parts of memory (as 32b is reserved for 64b result) thus making strange errors.

This is just an example one:
WatiN-2.1.0.1196/source/src/Core/Native/Windows/Win32.cs

public static extern Int32 SendMessageTimeout(IntPtr hWnd, Int32 msg, Int32 wParam, Int32 lParam, Int32 fuFlags, Int32 uTimeout, ref Int32 lpdwResult);

VS correct

public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint msg, UIntPtr wParam, IntPtr lParam, uint fuFlags, uint uTimeout, out IntPtr lResult);

For full change check http://pastebin.com/KaVpM6wT
It needs a rebuild of the Watin.Core dll of course and comes with no warranty.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文