简体   繁体   中英

Unit tests failing when large volume are run with Failed to write to an IPC Port

Update - It looks like there may be some kind of memory leak with Resharper running the tests. Not sure if it is my code or Resharper. Any suggestions on how to diagnose if there is a memory leak running the tests?

I have two C# test projects, one for my data layer and one for my webservice layer which is more of a full integration test. The basic format of the data layer project is as follows

  • 10 test classes, each testing one of my repository classes

  • Each test class has it's class initialisation of dropping and recreating the database with Entity Framework Code First, populating the basic user data, creating tables etc. So this is done 10 times across the entire data layer test project run. Quite heavy on DB I know but the best way to keep isolation of test data between classes

  • Each unit test method within each test class then populates the rest of the data required and removes the data at the end of each test. This results in a lot of duplication of data loading/removal each time a test is run but it's the cleanest way to ensure fresh data at the start of each test or I found the tests would interfere with each other a lot

The web service layer does the same but it drops and recreates the database in between each test. Off the top of my head I cant recall why I did it that way but there must have been a reason. Each test also creates a WCF service proxy to make the call to a locally instantiated WCF client.

Either way I would expect this to not result in any uncleaned up resources, but I appear to have a memory leak somewhere.

After a day of running tests yesterday the memory usage of visual studio was up to 1Gb and I'm having to reboot at least once most days at the moment or it eventually gets too slow.

I also find that if I run the entire test suite (250 tests) of both data and web together, once it gets to the last 40-50 tests, the tests all fail with

Unit Test Adapter threw exception: 
Failed to write to an IPC Port: The pipe is being closed.
.
-- Exception doesn't have a stack trace -- 

At which point I have to shut down Visual Studio and re-open it.

So something weird is going on. Can anyone suggest what I can look at to resolve this? I should be able to run 250 tests without it falling over from out of memory

Update: here is the exception - something to do with resharper maybe?

(JetBrains.ReSharper.TaskRunner.CLR4.exe, PID 7744, Thread 14) UnitTestAdapter.Run: unexpected error: execution thread for test 'DeleteVenueMenuCalendarRecurringItem' got exception while run was being aborted: System.Runtime.Remoting.RemotingException: Failed to write to an IPC Port: The pipe is being closed.


Server stack trace: 
   at System.Runtime.Remoting.Channels.Ipc.IpcPort.Write(Byte[] data, Int32 offset, Int32 size)
   at System.Runtime.Remoting.Channels.Ipc.PipeStream.Write(Byte[] buffer, Int32 offset, Int32 count)
   at System.Runtime.Remoting.Channels.ChunkedMemoryStream.WriteTo(Stream stream)
   at System.Runtime.Remoting.Channels.StreamHelper.CopyStream(Stream source, Stream target)
   at System.Runtime.Remoting.Channels.Ipc.IpcClientHandler.SendRequest(IMessage msg, ITransportHeaders headers, Stream contentStream)
   at System.Runtime.Remoting.Channels.Ipc.IpcClientTransportSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream)
   at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at JetBrains.ReSharper.TaskRunnerFramework.IRemoteTaskChannel.TaskOutput(String runId, RemoteTask remoteTask, String text, TaskOutputType outputType)
   at JetBrains.ReSharper.TaskRunnerFramework.TaskRunnerProxy.TaskOutput(RemoteTask remoteTask, String text, TaskOutputType outputType)
   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)

Exception rethrown at [1]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at JetBrains.ReSharper.TaskRunnerFramework.IRemoteTaskServer.TaskOutput(RemoteTask remoteTask, String text, TaskOutputType outputType)
   at JetBrains.ReSharper.TaskRunnerFramework.ThreadProxyTaskServer.<>c__DisplayClass10.<TaskOutput>b__f()
   at JetBrains.ReSharper.TaskRunnerFramework.ThreadProxyTaskServer.<>c__DisplayClass1c.<Execute>b__1b(Object state)
   at System.Threading.ExecutionContext.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at JetBrains.ReSharper.TaskRunnerFramework.ThreadProxyTaskServer.Execute(ExecutionDelegate task)
   at JetBrains.ReSharper.TaskRunnerFramework.ThreadProxyTaskServer.TaskOutput(RemoteTask remoteTask, String text, TaskOutputType outputType)
   at JetBrains.ReSharper.TaskRunnerFramework.ClientControllerServerWrapper.TaskOutput(RemoteTask remoteTask, String text, TaskOutputType outputType)
   at JetBrains.ReSharper.UnitTestRunner.MSTest.ResultSink.AddResult(TestMessage testMessage)
   at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapter.Run(ITestElement testElement, ITestContext testContext, Boolean 

How heavy is it to recreate the database, and how do you do it? If you always creates it to the same stat I would recommend using another way of setting up the database, you could use snapshots and just reset it before every test run. Or you should make the test able to run on the database independent on the state of the database.

Why does it crash VS? I don't know. I do not think there is a leak in the reshaper tool - but that is only a guess. Do you always get the same result when running the tests? Have you tried it on another machine?

To me it sound like you are running a integration test and not unit test. So perhaps VS on your local machine is not the right tool for that. I would recommend looking into using a continuous integration (CI) service to solve it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM