public void RemoteExecutorJoinWaitsForPulse() { var remoteServiceMock = new Mock<IRemoteExecutorService>(MockBehavior.Strict); const string MethodResult = "whatever"; var expectedResult = new RemoteExecutorServiceResult() { ExecutorState = ServiceReferences.ExecutorState.Finished, Result = MethodResult }; remoteServiceMock.Setup(rs => rs.Initialize(It.IsAny<byte[]>())).Returns(() => Guid.NewGuid()); remoteServiceMock.Setup(rs => rs.ExecuteAsync(It.IsAny<Guid>(), It.IsAny<object[]>(), It.IsAny<ServiceUri>())).Returns(() => Task.Run(() => { })); remoteServiceMock.Setup(rs => rs.TryJoin(It.IsAny<Guid>())).Returns(expectedResult); var executor = new RemoteExecutor(); executor.Setup(remoteServiceMock.Object, new ServiceUri()); executor.Initialize(() => MethodResult); executor.ExecutorState.ShouldBe(Bluepath.Executor.ExecutorState.NotStarted); executor.Execute(new object[0] { }); executor.ExecutorState.ShouldBe(Bluepath.Executor.ExecutorState.Running); var joinTask = Task.Run(() => { executor.Join(); }); joinTask.Wait(WaitTimeout).ShouldBe(false); executor.Pulse(expectedResult); joinTask.Wait(WaitTimeout).ShouldBe(true); executor.ExecutorState.ShouldBe(Bluepath.Executor.ExecutorState.Finished); executor.Result.ShouldBe(MethodResult); }
public void FakeRemoteExecutorCanUseCommunicationFrameworkSubsitutingParameterTest() { var testMethod = new Func<IBluepathCommunicationFramework, int, Guid>((bluepath, a) => bluepath.ProcessEid); testMethod.Method.IsStatic.ShouldBe(true); var executor = new RemoteExecutor(); executor.Setup(new FakeRemoteExecutorService(), null); executor.Initialize(testMethod); var eid = executor.Eid; executor.Execute(new object[] { null, 1 }); executor.Join(); var result = executor.GetResult(); result.ShouldBe(eid); Assert.IsTrue((Guid)result != Guid.Empty); }
public void FakeRemoteExecutorJoinTest() { const int DelayMilliseconds = 50; var testMethod = new Func<int, int, int, int>((a, b, delay) => { Thread.Sleep(delay); return a + b; }); testMethod.Method.IsStatic.ShouldBe(true); var executor = new RemoteExecutor(); executor.Setup(new FakeRemoteExecutorService(), null); executor.Initialize(testMethod); executor.ExecutorState.ShouldBe(ExecutorState.NotStarted); executor.Execute(new object[] { 1, 2, DelayMilliseconds }); executor.ExecutorState.ShouldBe(ExecutorState.Running); executor.Join(); executor.ExecutorState.ShouldBe(ExecutorState.Finished); var result = executor.GetResult(); result.ShouldBe(3); // (1 + 2) executor.ElapsedTime.Value.ShouldBeGreaterThanOrEqualTo(TimeSpan.FromMilliseconds(DelayMilliseconds)); }
public void FakeRemoteExecutorJoinWithExceptionTest() { var testMethod = new Func<int, int, int>((a, b) => { throw new Exception("test"); }); var executor = new RemoteExecutor(); executor.Setup(new FakeRemoteExecutorService(), null); executor.Initialize(testMethod); executor.Execute(new object[] { 1, 2 }); try { executor.Join(); Assert.Fail("Exception was expected but not thrown."); } catch (Exception ex) { executor.ExecutorState.ShouldBe(ExecutorState.Faulted); if (ex is RemoteException) { ex.InnerException.Message.Contains("System.Reflection.TargetInvocationException").ShouldBe(true); ex.InnerException.Message.Contains("System.Exception: test").ShouldBe(true); } else { Assert.Fail(string.Format("RemoteException was expected but another ('{0}') was thrown on local site.", ex.GetType())); } } }