public static async Task <T> PollForCondition <T>( this ITestScheduler scheduler, Func <T> getState, Func <T, bool> condition, CancellationToken cancellationToken) { var tcs = new TaskCompletionSource <T>(); void CheckCondition() { try { var state = getState(); if (condition(state)) { tcs.SetResult(state); } } catch (Exception e) { tcs.SetException(e); } } using (scheduler.RegisterPollCallback(CheckCondition)) using (cancellationToken.Register(tcs.SetCanceled)) { if (!cancellationToken.IsCancellationRequested) { CheckCondition(); // Complete immediately if already met } return(await tcs.Task); } }
public static Task <T> TimeoutAfter <T>( this ITestScheduler testScheduler, TimeSpan timeout, CancellationToken cancellationToken, DeferredTask <T> deferredTask) => cancellationToken.Amb( deferredTask, ct => testScheduler.Timeout(timeout, ct).ThrowResult <T>());
/// <summary> /// Sets the operator context for the timeline observable. /// </summary> /// <param name="context">The operator context.</param> /// <remarks> /// This operator is only expected to work with the remoting /// framework, specifically, a test query evaluator implementation /// designed to enable this operator. /// </remarks> public override void SetContext(IOperatorContext context) { _scheduler = (ITestScheduler)context.Scheduler; context.TryGetElement <TimelineStoreConnection>(TimelineStoreConnection.ContextHandle, out var eventTimelines); Debug.Assert(eventTimelines != null); eventTimelines.TryGetValue(Params._uri.ToCanonicalString(), out _events); context.TryGetElement <TestSubscriptionStoreConnection>(TestSubscriptionStoreConnection.ContextHandle, out _subscriptionStore); Debug.Assert(_subscriptionStore != null); base.SetContext(context); }
/// <summary> /// Constructs a new test instruction executor. /// </summary> /// <param name="scheduler">Implementation for time and frame based operations.</param> /// <param name="externalResultSource"> /// Optional source for premature completion of test operations. /// </param> /// <param name="failureListener"> /// Optional failure listener, to get notifications on test operation failures. /// </param> /// <param name="globalContextProvider"> /// Optional provider for global context, which gets included in failure messages. /// </param> public TestInstructionExecutor( ITestScheduler scheduler, IExternalResultSource externalResultSource = null, IFailureListener failureListener = null, IGlobalContextProvider globalContextProvider = null) { this.scheduler = scheduler; this.externalResultSource = externalResultSource; this.failureListener = failureListener; this.globalContextProvider = globalContextProvider; }
/// <summary> /// Constructs a new test instruction executor. /// </summary> /// <param name="scheduler">Implementation for time and frame based operations.</param> /// <param name="externalResultSource"> /// Optional source for premature completion of test operations. /// </param> /// <param name="failureListener"> /// Optional failure listener, to get notifications on test operation failures. /// </param> /// <param name="globalContextProvider"> /// Optional provider for global context, which gets included in failure messages. /// </param> /// <param name="rethrowableExceptions"> /// Optional collection of exception types to rethrow, instead of wrapping them in /// <see cref="TestFailureException"/>. /// Test instructions terminating with any of the given exception types will be considered /// completed, and not failed. Can be used with e.g. NUnit's <c>IgnoreException</c>. /// </param> public TestInstructionExecutor( ITestScheduler scheduler, IExternalResultSource externalResultSource = null, IFailureListener failureListener = null, IGlobalContextProvider globalContextProvider = null, IReadOnlyList <Type> rethrowableExceptions = null) { this.scheduler = scheduler; this.externalResultSource = externalResultSource; this.failureListener = failureListener; this.globalContextProvider = globalContextProvider; this.rethrowableExceptions = rethrowableExceptions; }
public static void ScheduleAbsolute(this ITestScheduler scheduler, long dueTime, Func <Task> asyncAction) { if (scheduler == null) { throw new ArgumentNullException(nameof(scheduler)); } if (asyncAction == null) { throw new ArgumentNullException(nameof(asyncAction)); } scheduler.ScheduleAbsolute(dueTime, new RemoteSchedulerTask(new AsyncClientAction(asyncAction))); }
private static async Task <Exception> Timeout( this ITestScheduler scheduler, TimeSpan timeout, CancellationToken cancellationToken) { var deadline = scheduler.TimeNow + timeout; var completionSource = new TaskCompletionSource <object>(); void CheckTimeout() { if (scheduler.TimeNow >= deadline) { completionSource.SetException(new TimeoutException()); } } using (scheduler.RegisterPollCallback(CheckTimeout)) using (cancellationToken.Register(completionSource.SetCanceled)) { return(await completionSource.Task.ExpectException()); } }
internal WaitContext(ITestScheduler scheduler) { this.scheduler = scheduler; this.startTime = scheduler.TimeNow; this.startFrame = scheduler.FrameNow; }
internal RunContext(SourceContext sourceContext, ITestScheduler scheduler) { this.SourceContext = sourceContext; this.Scheduler = scheduler; }
public DashboardService(IDataStore dataStore, ITestScheduler testScheduler) { _dataStore = dataStore; _testScheduler = testScheduler; }