华廷间歇性故障间歇性、故障

2023-09-08 10:33:49 作者:一人一城一生心疼

我的团队有一帮华廷测试套件,它通过我们的TeamCity服务器自动运行。最近,我们交换我们所有的生成代理的64位,我也打开了华廷测试使用NUnit的在64位模式。华廷一直给了我们不经常测试失败,因为失败的互操作调用IE浏览器或其他原因,但这些一直都是相当罕见。由于开关都为64位,我们的任何测试套件几乎所有的运行失败,出现以下异常:

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)
    ...

我发现了一个相关问题凡华廷用户看到了同样的异常,但正是因为她试图多线程。我们没有做任何这样的事情,事实上我们使用的是正确的线程状态公寓所建议的华廷文档。我的问题也注意到,虽然有人曾评论说,这可能是由于86与64位模式。

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?

如果它仅仅是切换回32位模式的问题,我能搞定,但我想知道肯定,有没有更好的解决办法。谢谢你。

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.

更新:的 离开工作岗位为使用64位NUnit的转轮的测试套件约5+运行后,他们每次都失败。只有一次,与此相同的错误。我们切换回至32位,并因为有过10+成功运行。我想对于现在的临时解决方法是使用一个32位NUnit的亚军,虽然我仍然在寻找出现这种情况的一个原因或解决方案,使我们能够切换到64位。

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.

推荐答案

我使用华廷在x64和它引起了我一些麻烦。我最近审查华廷源$ C ​​$ c和似乎的PInvoke调用是有缺陷的(工作仅32B系统正常)。如果执行某些方法,他们覆盖的内存某些部分(如32B是保留给64B的结果),这样奇怪的错误。

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.

这只是一个例子之一: 华廷-2.1.0.1196 /源/ src目录/核心/本地/窗/ Win32.cs

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正确

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,并配备了不予保修。

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