2

我想围绕托管 Edge.js 的 .NET 库创建单元测试,以进行 node.js 函数调用。

它因错误而失败,System.AccessViolationException我继续尝试在单元测试中使用 Edge 来重现该问题。

我能做到这一点,还是我不了解当前的限制?

为了重现,一个简单的单元测试

using System.Threading.Tasks;
using EdgeJs;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace UnitTest {
    [TestClass]
    public class UnitTest1 {
        [TestMethod]
        public void TestMethod1() {
            Start().Wait();
        }
        public static async Task<object> Start() {
            var func = Edge.Func(@"
                return function (data, cb) {
                    cb(null, 'Node.js ' + process.version + ' welcomes ' + data);
                }
            ");
            return await func("MSTEST");
        }
    }
}

并且 MSTEST 挂起并且输出的报告消息显示

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at _atexit_helper(IntPtr func, UInt32* __pexit_list_size, (fnptr)** __ponexitend_e, (fnptr)** __ponexitbegin_e)
   at _atexit_m(IntPtr func)
   at ClrFunc.Initialize(Local<v8::Function>* , Func`2 func)
   at ClrFunc.Initialize(FunctionCallbackInfo<v8::Value>* info)
   at initializeClrFunc(FunctionCallbackInfo<v8::Value>* info)
   at Nan.imp.?A0x8dda69af.FunctionCallbackWrapper(FunctionCallbackInfo<v8::Value>* info)
   at EdgeJs.Edge.NodeStartx86(Int32 argc, String[] argv)
   at EdgeJs.Edge.<>c__DisplayClass11_0.<Func>b__0()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
   at _atexit_helper(IntPtr func, UInt32* __pexit_list_size, (fnptr)** __ponexitend_e, (fnptr)** __ponexitbegin_e)
   at _atexit_m(IntPtr func)
   at ClrFunc.Initialize(Local<v8::Function>* , Func`2 func)
   at ClrFunc.Initialize(FunctionCallbackInfo<v8::Value>* info)
   at initializeClrFunc(FunctionCallbackInfo<v8::Value>* info)
   at Nan.imp.?A0x8dda69af.FunctionCallbackWrapper(FunctionCallbackInfo<v8::Value>* info)
   at EdgeJs.Edge.NodeStartx86(Int32 argc, String[] argv)
   at EdgeJs.Edge.<>c__DisplayClass11_0.<Func>b__0()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
4

0 回答 0