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);
                }
        }
示例#2
0
 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>());
示例#3
0
 /// <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);
 }
示例#4
0
 /// <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;
 }
示例#5
0
 /// <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;
 }
示例#6
0
        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)));
        }
示例#7
0
        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());
                }
        }
示例#8
0
 internal WaitContext(ITestScheduler scheduler)
 {
     this.scheduler  = scheduler;
     this.startTime  = scheduler.TimeNow;
     this.startFrame = scheduler.FrameNow;
 }
示例#9
0
 internal RunContext(SourceContext sourceContext, ITestScheduler scheduler)
 {
     this.SourceContext = sourceContext;
     this.Scheduler     = scheduler;
 }
示例#10
0
 public DashboardService(IDataStore dataStore, ITestScheduler testScheduler)
 {
     _dataStore     = dataStore;
     _testScheduler = testScheduler;
 }