Пример #1
0
        private RSession CreateRSession(string sessionId)
        {
            var session = new RSession(Interlocked.Increment(ref _sessionCounter), sessionId, Broker, _connectArwl.CreateExclusiveReaderLock(), () => DisposeSession(sessionId));

            session.Connected += RSessionOnConnected;
            return(session);
        }
Пример #2
0
        public async Task StartStop() {
            var session = new RSession(0, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { });

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

            await session.StartHostAsync(new RHostStartupInfo {
                Name = _testMethod.Name
            }, 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 {
                Name = _testMethod.Name
            }, null, 50000);

            session.HostStarted.Should().BeRanToCompletion();
            session.IsHostRunning.Should().BeTrue();
        }
Пример #3
0
 public CancelAll(TestMethodFixture testMethod, TaskObserverMethodFixture taskObserver) {
     _taskObserver = taskObserver;
     _testMethod = testMethod.MethodInfo;
     _brokerClient = CreateLocalBrokerClient(nameof(RSessionTest) + nameof(CancelAll));
     _callback = new RSessionCallbackStub();
     _session = new RSession(0, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => {});
 }
Пример #4
0
        private RSession CreateRSession(Guid guid)
        {
            var session = new RSession(Interlocked.Increment(ref _sessionCounter), Broker, () => DisposeSession(guid));

            session.Connected    += RSessionOnConnected;
            session.Disconnected += RSessionOnDisconnected;
            return(session);
        }
Пример #5
0
 public async Task CreateBlob_DisconnectedFromTheStart() {
     using (var session = new RSession(0, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { })) {
         var data = new byte[] { 1, 2, 3, 4, 5 };
         using (DataTransferSession dts = new DataTransferSession(session, null)) {
             Func<Task> f = () => dts.SendBytesAsync(data, false, null, CancellationToken.None);
             await f.ShouldThrowAsync<RHostDisconnectedException>();
         }
     }
 }
Пример #6
0
        public void Lifecycle() {
            var disposed = false;

            var session = new RSession(0, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => disposed = true);
            disposed.Should().BeFalse();

            session.MonitorEvents();

            session.Dispose();
            session.ShouldRaise("Disposed");
            disposed.Should().BeTrue();
        }
Пример #7
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();
        }
Пример #8
0
        public void Lifecycle() {
            var disposed = false;

            var session = new RSession(0, null, () => disposed = true);
            disposed.Should().BeFalse();

            session.MonitorEvents();

            session.Dispose();
            session.ShouldRaise("Disposed");
            disposed.Should().BeTrue();

            disposed = false;
            session.MonitorEvents();

            session.Dispose();
            session.ShouldNotRaise("Disposed");
            disposed.Should().BeFalse();
        }
Пример #9
0
        public async Task StartStop() {
            var session = new RSession(0, null, () => { });

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

            await session.StartHostAsync(new RHostStartupInfo {
                Name = _testMethod.Name,
                RBasePath = RUtilities.FindExistingRBasePath()
            }, 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();
        }
Пример #10
0
        public async Task StartStopMultipleSessions() {
            Func<int, Task<RSession>> start = async i => {
                var session = new RSession(i, null, () => { });
                await session.StartHostAsync(new RHostStartupInfo { Name = _testMethod.Name, RBasePath = RUtilities.FindExistingRBasePath()}, 50000);
                return session;
            };

            var sessions = await ParallelTools.InvokeAsync(4, start);
            sessions.Should().OnlyContain(s => s.IsHostRunning);

            await ParallelTools.InvokeAsync(4, i => sessions[i].StopHostAsync());
            sessions.Should().OnlyContain(s => !s.IsHostRunning);
        }
Пример #11
0
        public async Task StopReentrantLoop() {
            var callback = new RSessionCallbackStub();
            var session = new RSession(0, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { });

            await session.StartHostAsync(new RHostStartupInfo {
                Name = _testMethod.Name
            }, 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();
        }
 public CancelAll(TestMethodFixture testMethod) {
     _testMethodFixture = testMethod;
     _testMethod = testMethod.MethodInfo;
     _session = new RSession(0, null, () => {});
 }
Пример #13
0
 public BeforeInitializedRExpressionEvaluator(RSession session)
 {
     _session = session;
 }
 public async Task BeginInteractionAsync_DisconnectedFromTheStart() {
     using (var session = new RSession(0, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { })) {
         // ReSharper disable once AccessToDisposedClosure
         Func<Task> f = () => session.BeginInteractionAsync();
         await f.ShouldThrowAsync<RHostDisconnectedException>();
     }
 }
 public InteractionEvaluation(TestMethodFixture testMethod) {
     _testMethod = testMethod.Method;
     _session = new RSession(0, null, () => {});
 }
Пример #16
0
        public void StartRHostMissing() {
            var session = new RSession(0, null, () => { });
            Func<Task> start = () => session.StartHostAsync(new RHostStartupInfo {
                Name = _testMethod.Name,
                RHostDirectory = Environment.SystemDirectory
            }, 10000);

            start.ShouldThrow<RHostBinaryMissingException>();
        }
Пример #17
0
        public async Task StopBeforeInitialized() {
            var session = new RSession(0, null, () => { });
            Func<Task> start = () => session.StartHostAsync(new RHostStartupInfo {
                Name = _testMethod.Name,
                RHostDirectory = Environment.SystemDirectory
            }, 10000);

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

            session.IsHostRunning.Should().BeFalse();
        }
Пример #18
0
        public async Task Start_KillProcess_Start() {
            var session = new RSession(0, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { });

            session.HostStarted.Should().NotBeCompleted();
            session.IsHostRunning.Should().BeFalse();
            
            await session.StartHostAsync(new RHostStartupInfo {
                Name = _testMethod.Name
            }, null, 50000);

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

            var sessionDisconnectedTask = EventTaskSources.IRSession.Disconnected.Create(session);
            var processId = await GetRSessionProcessId(session);
            Process.GetProcessById(processId).Kill();
            await sessionDisconnectedTask;

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

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

            session.HostStarted.Should().BeRanToCompletion();
            session.IsHostRunning.Should().BeTrue();
        }
Пример #19
0
        public async Task DoubleStart() {
            var session = new RSession(0, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { });
            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();
        }
Пример #20
0
 public async Task DestroyBlob_DisconnectedFromTheStart() {
     using (var session = new RSession(0, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { })) {
         var blobids = new ulong[] { 1, 2, 3, 4, 5 };
         Func<Task> f = () => session.DestroyBlobsAsync(blobids);
         await f.ShouldThrowAsync<RHostDisconnectedException>();
     }
 }
Пример #21
0
        public async Task StartStopMultipleSessions() {
            Func<int, Task<RSession>> start = async i => {
                var session = new RSession(i, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { });
                await session.StartHostAsync(new RHostStartupInfo { Name = _testMethod.Name + i }, null, 50000);
                return session;
            };

            var sessionsTasks = await ParallelTools.InvokeAsync(4, start, 50000);

            sessionsTasks.Should().OnlyContain(t => t.Status == TaskStatus.RanToCompletion);
            var sessions = sessionsTasks.Select(t => t.Result).ToList();
            sessions.Should().OnlyContain(t => t.IsHostRunning);

            var sessionStopTasks = await ParallelTools.InvokeAsync(4, i => sessionsTasks[i].Result.StopHostAsync());
            sessionStopTasks.Should().OnlyContain(t => t.Status == TaskStatus.RanToCompletion);
            sessions.Should().OnlyContain(t => !t.IsHostRunning);
        }
Пример #22
0
 public async Task GetBlob_DisconnectedFromTheStart() {
     using (var session = new RSession(0, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { })) {
         Func<Task> f = () => session.BlobReadAllAsync(1);
         await f.ShouldThrowAsync<RHostDisconnectedException>();
     }
 }
Пример #23
0
        public void StartRHostMissing() {
            var brokerClient = new LocalBrokerClient(nameof(RSessionTest), @"C:\", TestCoreServices.CreateReal(), new NullConsole(), Environment.SystemDirectory);
            var session = new RSession(0, brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { });
            Func<Task> start = () => session.StartHostAsync(new RHostStartupInfo {
                Name = _testMethod.Name
            }, null, 10000);

            start.ShouldThrow<RHostBrokerBinaryMissingException>();
        }
Пример #24
0
 private RSession CreateRSession(Guid guid) {
     var session = new RSession(Interlocked.Increment(ref _sessionCounter), Broker, _connectArwl.CreateExclusiveReaderLock(), () => DisposeSession(guid));
     session.Connected += RSessionOnConnected;
     return session;
 }
Пример #25
0
        public async Task StopBeforeInitialized() {
            var session = new RSession(0, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { });
            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;
        }
 public InteractionEvaluation(TestMethodFixture testMethod, TaskObserverMethodFixture taskObserver) {
     _taskObserver = taskObserver;
     _testMethod = testMethod.MethodInfo;
     _brokerClient = CreateLocalBrokerClient(nameof(RSessionTest) + nameof(InteractionEvaluation));
     _session = new RSession(0, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { });
 }
Пример #27
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, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { });
            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;
        }
Пример #28
0
 public BrokerTransaction(RSession session)
 {
     _session = session;
 }
Пример #29
0
 public Output(TestMethodFixture testMethod) {
     _testMethod = testMethod.MethodInfo;
     _brokerClient = CreateLocalBrokerClient(nameof(RSessionTest) + nameof(Output));
     _session = new RSession(0, _brokerClient, new AsyncReaderWriterLock().CreateExclusiveReaderLock(), () => { });
 }