Completed
Last Updated: 17 May 2013 12:44 by Jakub
Jakub
Created on: 02 Jan 2013 16:11
Type: Bug Report
0
Exception when running test in more than one thread
When I try to invoke method from intercepted class in multi-thread test sometimes I get following exception:
System.ArgumentException
Destination array was not long enough. Check destIndex and length, and the array's lower bounds.
   at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
   at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length)
   at System.Collections.Generic.List`1.CopyTo(T[] array, Int32 arrayIndex)
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList(IEnumerable`1 source)
   at Telerik.JustMock.Weaver.ContainerContext.InstanceIdentifier.GetUniqueId(Object target)
   at Telerik.JustMock.Weaver.ContainerContext.Get(Type targetType, MethodBase methodInfo, Object target)
   at Telerik.JustMock.Weaver.ContainerContext.Get(MethodBase methodBase, Object target)
   at Telerik.JustMock.Weaver.Interceptors.WeaverInterceptor.OnInvocation(IInvocation invocation)
   at Telerik.JustMock.Weaver.Interceptors.WeaverInterceptor.Telerik.JustMock.Weaver.Interceptors.Abstraction.IWeaverInterceptor.Intercept(IInvocation invocation)
   at TestClass_Interceptor_620e5e80fe0c4d738f7ef291ea50ea2a.Intercept(TestClass, ref Boolean)
   at ExceptionExample.TestClass.ExecuteSomething() in Test.cs: line 174
   at ExceptionExample.RunMethod() in Test.cs: line 199
   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()


Sample class that generates exception:

[TestFixture]
public class ExceptionExample
{
	static ExceptionExample()
	{
		Mock.Initialize<TestClass>();
	}

	public class TestClass
	{
		public void ExecuteSomething()
		{
			int y = 0;
			for (int i = 0; i < 100; i++)
				y += i;
		}
	}

	[Test]
	public void MethodName()
	{
		List<Thread> l = new List<Thread>();

		for (int i = 0; i < 6; i++)
		{
			Thread t = new Thread(RunMethod);
			t.Start();
			l.Add(t);
		}

		l.ForEach(th => th.Join());
	}

	private void RunMethod()
	{
		for (int i = 0; i < 10000; i++)
		{
			TestClass tc1 = new TestClass();
			tc1.ExecuteSomething();
		}
	}
}
0 comments