示例#1
0
        public void WaitForOperatorThrowsTimeoutExceptionAfterTimeOut()
        {
            var scheduler = new TestFacade();

            var synced = new Synced <Exception>();

            async CTask Do()
            {
                var source    = new Source <int>();
                var waitedFor = source.WaitFor(5, true, TimeSpan.FromMilliseconds(500));

                try
                {
                    await waitedFor;
                }
                catch (Exception e)
                {
                    synced.Value = e;
                }
            }

            synced.Value.ShouldBeNull();

            scheduler.Schedule(() => _ = Do());

            var exception = synced.WaitFor(e => e != null);

            (exception is TimeoutException).ShouldBeTrue();

            scheduler.Dispose();
        }
        public void WaitForOperatorEmitsElementsBeforeTimeOutDespiteRestart()
        {
            var facade = new TestFacade();

            var synced = new Synced <WaitForWorkflow>();

            facade.Schedule(() =>
            {
                var workflow = new WaitForWorkflow(5000);

                Sync.AfterNext(workflow.EmitEventsToSource, true);
                Sync.AfterNext(workflow.SetFieldVariableAfterWaitedFor, true);
            });

            Thread.Sleep(100);

            facade.PersistAndCloseDown();

            Thread.Sleep(100);

            facade.LoadAgain();

            Thread.Sleep(3000);

            synced.Value.ShouldBeNull();

            var w = facade.Resolve <WaitForWorkflow>();

            w.Emits.ToArray().Length.ShouldBe(5);

            facade.Dispose();
        }
        public void WaitForOperatorEmitsElementsThrowsExceptionDespiteRestart()
        {
            var facade = new TestFacade();

            var synced = new Synced <Exception>();

            facade.Schedule(() =>
            {
                var workflow = new WaitForWorkflow(1000);
                Sync.AfterNext(workflow.EmitEventsToSource, true);
                Sync.AfterNext(workflow.SetFieldVariableAfterWaitedFor, true);
            });

            Thread.Sleep(100);

            facade.PersistAndCloseDown();

            Thread.Sleep(100);

            facade.LoadAgain();

            Thread.Sleep(3000);

            synced.Value.ShouldBeNull();

            var thrownException = facade.Resolve <WaitForWorkflow>().ThrownException;

            (thrownException is TimeoutException).ShouldBeTrue();

            facade.Dispose();
        }
        public async Task SimpleWaitForWithTimeoutTest()
        {
            var facade = new TestFacade();

            _ = facade.Schedule(() =>
            {
                var w = new SimpleWaitForWorkflow();
                Roots.Entangle(w);
                _ = w.Start();
            });

            await facade.Scheduler.Sync();

            var workflow = facade.Resolve <SimpleWaitForWorkflow>();

            workflow.ThrownException.ShouldBeNull();
            facade.LoadAgain();

            await Task.Delay(3000);

            workflow = facade.Resolve <SimpleWaitForWorkflow>();
            workflow.ThrownException.ShouldNotBeNull();

            facade.Dispose();
        }