/// <summary> /// Cannot use await calls here since this is used directly by TAEF test methods which don't support that /// </summary> public virtual void Execute() { var cts = new CancellationTokenSource(); ManualResetEventSlim coordinatorStopped = new ManualResetEventSlim(); Task <int> t1 = Task.Run(() => { Coordinator.RunAsync(0, cts.Token).ContinueWith(_ => coordinatorStopped.Set()); Run(cts.Token); return(0); }); Task <int> t2 = Task.Run(() => { Thread.Sleep(TimeSpan.FromSeconds(TestExecutionTimeInSeconds)); return(-1); }); Task <int> t = Task.WhenAny(t1, t2).GetAwaiter().GetResult(); int status = t.GetAwaiter().GetResult(); cts.Cancel(); // Wait for the IS to return gracefully Assert.IsTrue(coordinatorStopped.Wait(TimeSpan.FromSeconds(5)), "Verify if coordinator stopped gracefully"); Assert.AreEqual(status, 0, "Verifying if test completed execution and didn't time out"); traceType.ConsoleWriteLine("Completed executing workflow. Time taken: {0}", stopwatch.Elapsed); }
private MockPropertyBatchResultWrapper WorkflowForInitializeTest1( Uri parentName, ICollection <PropertyBatchOperation> operations) { var result = new MockPropertyBatchResultWrapper { FailedOperationIndex = -1, FailedOperationException = new FabricException(FabricErrorCode.Unknown) }; result.NamedProperties.Add(new MockNamedPropertyWrapper { Value = (Int64)1 }); result.NamedProperties.Add(new MockNamedPropertyWrapper { Value = JobBlockingPolicy.BlockAllJobs.ToString() }); TraceType.ConsoleWriteLine("Setting FailedOperationIndex = -1 to simulate success from SubmitPropertyBatchAsync inside Initialize"); return(result); }
private MockPropertyBatchResultWrapper Workflow1( Uri parentName, ICollection <PropertyBatchOperation> operations) { var result = new MockPropertyBatchResultWrapper { FailedOperationIndex = -1, }; result.NamedProperties.Add(new MockNamedPropertyWrapper { Value = (Int64)2 }); result.NamedProperties.Add(new MockNamedPropertyWrapper { Value = "Apple" }); traceType.ConsoleWriteLine("Setting FailedOperationIndex = -1 to simulate success from SubmitPropertyBatchAsync for a Get"); workflow1Counter++; return(result); }
public virtual void Execute() { var cts = new CancellationTokenSource(); Coordinator.RunAsync(0, cts.Token); CompletedEvent.WaitOne(TimeSpan.FromSeconds(TestExecutionTimeInSeconds)); cts.Cancel(); // Wait for the IS to return gracefully Task.Delay(TimeSpan.FromSeconds(2)).Wait(); traceType.ConsoleWriteLine("Completed executing workflow. Time taken: {0}", stopwatch.Elapsed); }