Esempio n. 1
0
            public async Task DisposeAsync()
            {
                await _session.StopHostAsync();

                _session.Dispose();
                _brokerConnector.Dispose();
            }
Esempio n. 2
0
            public async Task DisposeAsync()
            {
                await _session.StopHostAsync();

                _session.Dispose();
                _brokerClient.Dispose();
            }
Esempio n. 3
0
            public async Task DisposeAsync()
            {
                await _session.StopHostAsync().Should().BeCompletedAsync();

                _session.Dispose();
                _brokerClient.Dispose();
            }
Esempio n. 4
0
        public async Task StopReentrantLoop()
        {
            var callback = new RSessionCallbackStub();
            var session  = new RSession(0, _testMethod.FileSystemSafeName, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { });

            await session.StartHostAsync(new RHostStartupInfo(), callback, 50000);

            var testMrs = new AsyncManualResetEvent();

            callback.PlotHandler = (message, ct) => {
                testMrs.Set();
                return(session.EvaluateAsync("x <- 1\n"));
            };

            Task responceTask;

            using (var interaction = await session.BeginInteractionAsync()) {
                responceTask = interaction.RespondAsync("plot(1)\n");
            }

            await testMrs.WaitAsync().Should().BeCompletedAsync();

            await session.StopHostAsync().Should().BeCompletedAsync(20000);

            session.IsHostRunning.Should().BeFalse();

            await responceTask.Should().BeCanceledAsync();
        }
Esempio n. 5
0
        public async Task StartStop()
        {
            var session = new RSession(0, _brokerClient, () => { });

            session.HostStarted.Status.Should().Be(TaskStatus.WaitingForActivation);
            session.IsHostRunning.Should().BeFalse();

            await session.StartHostAsync(new RHostStartupInfo {
                Name = _testMethod.Name
            }, null, 50000);

            session.HostStarted.Status.Should().Be(TaskStatus.RanToCompletion);
            session.IsHostRunning.Should().BeTrue();

            await session.StopHostAsync();

            session.HostStarted.Status.Should().Be(TaskStatus.WaitingForActivation);
            session.IsHostRunning.Should().BeFalse();

            await session.StartHostAsync(new RHostStartupInfo {
                Name = _testMethod.Name
            }, null, 50000);

            session.HostStarted.Status.Should().Be(TaskStatus.RanToCompletion);
            session.IsHostRunning.Should().BeTrue();
        }
Esempio n. 6
0
        public async Task StopBeforeInitialized()
        {
            var         session   = new RSession(0, _testMethod.FileSystemSafeName, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { });
            Func <Task> start     = () => session.StartHostAsync(new RHostStartupInfo(), null, 10000);
            var         startTask = Task.Run(start);

            await session.StopHostAsync();

            session.IsHostRunning.Should().BeFalse();

            await startTask;
        }
Esempio n. 7
0
        public async Task StopBeforeInitialized()
        {
            var         session = new RSession(0, () => { });
            Func <Task> start   = () => session.StartHostAsync(new RHostStartupInfo {
                Name           = _testMethod.Name,
                RHostDirectory = Environment.SystemDirectory
            }, null, 10000);

            Task.Run(start).DoNotWait();
            await session.StopHostAsync();

            session.IsHostRunning.Should().BeFalse();
        }
Esempio n. 8
0
        public async Task StopBeforeInitialized_RHostMissing()
        {
            var         brokerClient = new LocalBrokerClient(nameof(RSessionTest), BrokerConnectionInfo.Create(null, "C", @"C:\"), _services, new NullConsole(), Environment.SystemDirectory);
            var         session      = new RSession(0, _testMethod.FileSystemSafeName, brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { });
            Func <Task> start        = () => session.StartHostAsync(new RHostStartupInfo(), null, 10000);
            var         startTask    = Task.Run(start).SilenceException <RHostBinaryMissingException>();

            await session.StopHostAsync();

            session.IsHostRunning.Should().BeFalse();

            await startTask;
        }
Esempio n. 9
0
        public async Task StopBeforeInitialized()
        {
            var session = new RSession(0, _brokerConnector, () => { });

            session.BrokerConnector.SwitchToLocalBroker(nameof(RSessionTest), @"C:\", Environment.SystemDirectory);
            Func <Task> start = () => session.StartHostAsync(new RHostStartupInfo {
                Name = _testMethod.Name
            }, null, 10000);

            Task.Run(start).DoNotWait();
            await session.StopHostAsync();

            session.IsHostRunning.Should().BeFalse();
        }
Esempio n. 10
0
        public async Task StopBeforeInitialized()
        {
            var         session = new RSession(0, _brokerClient, () => { });
            Func <Task> start   = () => session.StartHostAsync(new RHostStartupInfo {
                Name = _testMethod.Name
            }, null, 10000);
            var startTask = Task.Run(start);

            await session.StopHostAsync();

            session.IsHostRunning.Should().BeFalse();

            await startTask;
        }
Esempio n. 11
0
        public async Task StopBeforeInitialized_RHostMissing()
        {
            var brokerClient = new LocalBrokerClient(nameof(RSessionTest), @"C:\",
                                                     TestCoreServices.CreateReal(), new NullConsole(), Environment.SystemDirectory);
            var         session = new RSession(0, brokerClient, () => { });
            Func <Task> start   = () => session.StartHostAsync(new RHostStartupInfo {
                Name = _testMethod.Name
            }, null, 10000);
            var startTask = Task.Run(start).SilenceException <RHostBrokerBinaryMissingException>();

            await session.StopHostAsync();

            session.IsHostRunning.Should().BeFalse();

            await startTask;
        }
Esempio n. 12
0
        public async Task DoubleStart()
        {
            var         session = new RSession(0, _testMethod.FileSystemSafeName, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { });
            Func <Task> start   = () => session.StartHostAsync(new RHostStartupInfo(), null, 50000);

            var tasks = await ParallelTools.InvokeAsync(4, i => start(), 50000);

            tasks.Should().ContainSingle(t => t.Status == TaskStatus.RanToCompletion);

            await session.HostStarted;

            session.IsHostRunning.Should().BeTrue();

            await session.StopHostAsync();

            session.IsHostRunning.Should().BeFalse();
        }
Esempio n. 13
0
        public async Task DoubleStart()
        {
            var         session = new RSession(0, _brokerClient, () => { });
            Func <Task> start   = () => session.StartHostAsync(new RHostStartupInfo {
                Name = _testMethod.Name
            }, null, 50000);

            var tasks = await ParallelTools.InvokeAsync(4, i => start(), 50000);

            tasks.Should().ContainSingle(t => t.Status == TaskStatus.RanToCompletion);

            await session.HostStarted;

            session.IsHostRunning.Should().BeTrue();

            await session.StopHostAsync();

            session.IsHostRunning.Should().BeFalse();
        }
Esempio n. 14
0
        public async Task DoubleStart()
        {
            var         session = new RSession(0, _brokerConnector, () => { });
            Func <Task> start   = () => session.StartHostAsync(new RHostStartupInfo {
                Name = _testMethod.Name
            }, null, 50000);

            Func <Task> f = () => ParallelTools.InvokeAsync(4, i => start());

            f.ShouldThrow <InvalidOperationException>();

            await session.HostStarted;

            session.IsHostRunning.Should().BeTrue();

            await session.StopHostAsync();

            session.IsHostRunning.Should().BeFalse();
        }
Esempio n. 15
0
        public async Task StartStop()
        {
            var session = new RSession(0, () => { });

            session.HostStarted.Status.Should().Be(TaskStatus.Canceled);
            session.IsHostRunning.Should().BeFalse();

            await session.StartHostAsync(new RHostStartupInfo {
                Name      = _testMethod.Name,
                RBasePath = RUtilities.FindExistingRBasePath()
            }, null, 50000);

            session.HostStarted.Status.Should().Be(TaskStatus.RanToCompletion);
            session.IsHostRunning.Should().BeTrue();

            await session.StopHostAsync();

            session.HostStarted.Status.Should().Be(TaskStatus.Canceled);
            session.IsHostRunning.Should().BeFalse();
        }
Esempio n. 16
0
        public async Task DoubleStart()
        {
            var         session = new RSession(0, null, () => { });
            Func <Task> start   = () => session.StartHostAsync(new RHostStartupInfo {
                Name      = _testMethod.Name,
                RBasePath = RUtilities.FindExistingRBasePath()
            }, 50000);

            Func <Task> f = () => ParallelTools.InvokeAsync(4, i => start());

            f.ShouldThrow <InvalidOperationException>();

            await session.HostStarted;

            session.IsHostRunning.Should().BeTrue();

            await session.StopHostAsync();

            session.IsHostRunning.Should().BeFalse();
        }
Esempio n. 17
0
        public async Task StartStop()
        {
            var session = new RSession(0, _testMethod.FileSystemSafeName, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { });

            session.HostStarted.Should().NotBeCompleted();
            session.IsHostRunning.Should().BeFalse();

            await session.StartHostAsync(new RHostStartupInfo(), null, 50000);

            session.HostStarted.Should().BeRanToCompletion();
            session.IsHostRunning.Should().BeTrue();

            await session.StopHostAsync();

            session.HostStarted.Should().NotBeCompleted();
            session.IsHostRunning.Should().BeFalse();

            await session.StartHostAsync(new RHostStartupInfo(), null, 50000);

            session.HostStarted.Should().BeRanToCompletion();
            session.IsHostRunning.Should().BeTrue();
        }
Esempio n. 18
0
 public Task StopSessionAsync()
 => RSession?.StopHostAsync(waitForShutdown: false) ?? Task.CompletedTask;