public async Task SwitchBroker_DisposeSessionProvider(int timeout) { var sessionProvider = new RSessionProvider(_services); var session1 = sessionProvider.GetOrCreate(nameof(SwitchBroker_DisposeSessionProvider) + 1); var session2 = sessionProvider.GetOrCreate(nameof(SwitchBroker_DisposeSessionProvider) + 2); session2.RestartOnBrokerSwitch = true; await sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchBroker_DisposeSessionProvider)); await session1.EnsureHostStartedAsync(new RHostStartupInfo(), null, 5000).Should().BeCompletedAsync(); await session2.HostStarted.Should().BeCompletedAsync(); var sessionProviderDisposeTask = Task.Delay(timeout).ContinueWith(t => sessionProvider.Dispose()); var stopwatch = new Stopwatch(); stopwatch.Start(); var result = await sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchBroker_DisposeSessionProvider) + "1"); stopwatch.Stop(); await sessionProviderDisposeTask; result.Should().Be(stopwatch.ElapsedMilliseconds < timeout); }
public async Task ConnectWhenSwitching() { using (var sessionProvider = new RSessionProvider(TestCoreServices.CreateReal())) { var guid1 = new Guid(); var guid2 = new Guid(); var session1 = sessionProvider.GetOrCreate(guid1); var session2 = sessionProvider.GetOrCreate(guid2); var switchTask = sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(ConnectWhenSwitching)); var startHost1Task = Task.Delay(50).ContinueWith(t => session1.EnsureHostStartedAsync(new RHostStartupInfo { Name = nameof(session1) }, null, 1000)).Unwrap(); var startHost2Task = Task.Delay(100).ContinueWith(t => session2.EnsureHostStartedAsync(new RHostStartupInfo { Name = nameof(session2) }, null, 1000)).Unwrap(); await Task.WhenAll(switchTask, startHost1Task, startHost2Task); startHost1Task.Should().BeRanToCompletion(); startHost2Task.Should().BeRanToCompletion(); await Task.WhenAll(session1.HostStarted, session2.HostStarted); } }
public void GetOrCreate() { using (var sessionProvider = new RSessionProvider(TestCoreServices.CreateReal())) { var guid = new Guid(); var session1 = sessionProvider.GetOrCreate(guid); session1.Should().NotBeNull(); var session2 = sessionProvider.GetOrCreate(guid); session2.Should().BeSameAs(session1); session1.Dispose(); var session3 = sessionProvider.GetOrCreate(guid); session3.Should().NotBeSameAs(session1); session3.Id.Should().NotBe(session1.Id); } }
private async Task <IEnumerable <string> > GraphicsTestAsync(string[] inputs) { using (var sessionProvider = new RSessionProvider()) { var session = sessionProvider.GetOrCreate(Guid.NewGuid(), new RHostClientTestApp { PlotHandler = OnPlot }); await session.StartHostAsync(new RHostStartupInfo { Name = _testMethod.Name, RBasePath = RUtilities.FindExistingRBasePath() }, 50000); foreach (var input in inputs) { using (var interaction = await session.BeginInteractionAsync()) { await interaction.RespondAsync(input + "\n"); } } await session.StopHostAsync(); } // Ensure that all plot files created by the graphics device have been deleted foreach (var deletedFilePath in OriginalPlotFilePaths) { File.Exists(deletedFilePath).Should().BeFalse(); } return(PlotFilePaths.AsReadOnly()); }
public async Task SwitchWhenConnecting() { using (var sessionProvider = new RSessionProvider(TestCoreServices.CreateReal())) { var guid = new Guid(); var session = sessionProvider.GetOrCreate(guid); await sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchWhenConnecting)); var startHostTask = session.EnsureHostStartedAsync(new RHostStartupInfo { Name = nameof(session) }, null, 1000); await Task.Yield(); var switch1Task = sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchWhenConnecting) + "1"); var switch2Task = sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchWhenConnecting) + "2"); await Task.WhenAll(startHostTask, switch1Task, switch2Task); switch1Task.Status.Should().Be(TaskStatus.RanToCompletion); switch2Task.Status.Should().Be(TaskStatus.RanToCompletion); startHostTask.Status.Should().Be(TaskStatus.RanToCompletion); await session.HostStarted; session.HostStarted.Should().BeRanToCompletion(); } }
private async Task <IEnumerable <string> > ExportToPdfAsync(string[] inputs, string filePath, int width, int height) { var app = new RHostClientTestApp { PlotHandler = OnPlot }; using (var sessionProvider = new RSessionProvider()) { var session = sessionProvider.GetOrCreate(Guid.NewGuid(), _brokerConnector); await session.StartHostAsync(new RHostStartupInfo { Name = _testMethod.Name }, app, 50000); foreach (var input in inputs) { using (var interaction = await session.BeginInteractionAsync()) { await interaction.RespondAsync(input + "\n"); } } string script = String.Format("rtvs:::export_to_pdf({0}, {1})", width, height); var data = await session.EvaluateAsync <byte[]>(script, REvaluationKind.Normal); File.WriteAllBytes(filePath, data); await session.StopHostAsync(); } // Ensure that all plot files created by the graphics device have been deleted foreach (var plot in OriginalPlotMessages) { File.Exists(plot.FilePath).Should().BeFalse(); } return(PlotFilePaths.AsReadOnly()); }
private async Task <IEnumerable <string> > ExportToImageAsync(string[] inputs, string[] format, string[] paths, int widthInPixels, int heightInPixels, int resolution) { var app = new RHostClientTestApp { PlotHandler = OnPlot }; using (var sessionProvider = new RSessionProvider()) { var session = sessionProvider.GetOrCreate(Guid.NewGuid(), _brokerConnector); await session.StartHostAsync(new RHostStartupInfo { Name = _testMethod.Name }, app, 50000); foreach (var input in inputs) { using (var interaction = await session.BeginInteractionAsync()) { await interaction.RespondAsync(input + "\n"); } } for (int i = 0; i < format.Length; ++i) { await ExportToImageAsync(session, format[i], paths[i], widthInPixels, heightInPixels, resolution); } await session.StopHostAsync(); } // Ensure that all plot files created by the graphics device have been deleted foreach (var plot in OriginalPlotMessages) { File.Exists(plot.FilePath).Should().BeFalse(); } return(PlotFilePaths.AsReadOnly()); }
public void GetOrCreate() { using (var sessionProvider = new RSessionProvider(_services)) { var guid = Guid.NewGuid().ToString(); var session1 = sessionProvider.GetOrCreate(guid); session1.Should().NotBeNull(); var session2 = sessionProvider.GetOrCreate(guid); session2.Should().BeSameAs(session1); session1.Dispose(); var session3 = sessionProvider.GetOrCreate(guid); session3.Should().NotBeSameAs(session1); session3.Id.Should().NotBe(session1.Id); } }
private async Task <IEnumerable <string> > ExportToImageAsync(string[] inputs, string[] format, string[] paths, int widthInPixels, int heightInPixels, int resolution) { var app = new RHostClientTestApp { PlotHandler = OnPlot, PlotDeviceCreateHandler = OnDeviceCreate, PlotDeviceDestroyHandler = OnDeviceDestroy }; using (var sessionProvider = new RSessionProvider(_services)) { await sessionProvider.TrySwitchBrokerAsync(nameof(IdeGraphicsDeviceTest)); var session = sessionProvider.GetOrCreate(_testMethod.FileSystemSafeName); await session.StartHostAsync(new RHostStartupInfo(), app, 50000); foreach (var input in inputs) { using (var interaction = await session.BeginInteractionAsync()) { await interaction.RespondAsync(input.EnsureLineBreak()); } } for (int i = 0; i < format.Length; ++i) { await ExportToImageAsync(session, format[i], paths[i], widthInPixels, heightInPixels, resolution); } await session.StopHostAsync(); } // Ensure that all plot files created by the graphics device have been deleted foreach (var plot in OriginalPlotMessages) { File.Exists(plot.FilePath).Should().BeFalse(); } return(PlotFilePaths.AsReadOnly()); }
public CallStackTest(TestMethodFixture testMethod) { _testMethod = testMethod.MethodInfo; _brokerConnector = new RHostBrokerConnector(); _brokerConnector.SwitchToLocalBroker(nameof(CallStackTest)); _sessionProvider = new RSessionProvider(); _session = _sessionProvider.GetOrCreate(Guid.NewGuid(), _brokerConnector); }
public async Task ConnectWhenSwitching() { using (var sessionProvider = new RSessionProvider(_services)) { var session1 = sessionProvider.GetOrCreate(nameof(ConnectWhenSwitching) + 1); var session2 = sessionProvider.GetOrCreate(nameof(ConnectWhenSwitching) + 2); var switchTask = sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(ConnectWhenSwitching)); var startHost1Task = Task.Delay(50).ContinueWith(t => session1.EnsureHostStartedAsync(new RHostStartupInfo(), null, 1000)).Unwrap(); var startHost2Task = Task.Delay(100).ContinueWith(t => session2.EnsureHostStartedAsync(new RHostStartupInfo(), null, 1000)).Unwrap(); await ParallelTools.WhenAll(30000, switchTask, startHost1Task, startHost2Task); startHost1Task.Should().BeRanToCompletion(); startHost2Task.Should().BeRanToCompletion(); await ParallelTools.WhenAll(30000, session1.HostStarted, session2.HostStarted); } }
public void GetOrCreate() { var sessionProvider = new RSessionProvider(); var guid = new Guid(); var session1 = sessionProvider.GetOrCreate(guid, null); session1.Should().NotBeNull(); var session2 = sessionProvider.GetOrCreate(guid, null); session2.Should().BeSameAs(session1); session1.Dispose(); var session3 = sessionProvider.GetOrCreate(guid, null); session3.Should().NotBeSameAs(session1); session3.Id.Should().NotBe(session1.Id); }
public void ParallelAccess() { using (var sessionProvider = new RSessionProvider()) { var guids = new[] { new Guid(), new Guid() }; ParallelTools.Invoke(100, i => { var session = sessionProvider.GetOrCreate(guids[i % 2], _brokerConnector); session.Dispose(); }); } }
public void ParallelAccess() { using (var sessionProvider = new RSessionProvider(_services)) { var guids = new[] { nameof(ParallelAccess) + 1, nameof(ParallelAccess) + 2 }; ParallelTools.Invoke(100, i => { var session = sessionProvider.GetOrCreate(guids[i % 2]); session.Dispose(); }); } }
public void ParallelAccess() { using (var sessionProvider = new RSessionProvider(TestCoreServices.CreateReal())) { var guids = new[] { new Guid(), new Guid() }; ParallelTools.Invoke(100, i => { var session = sessionProvider.GetOrCreate(guids[i % 2]); session.Dispose(); }); } }
public void Lifecycle() { var sessionProvider = new RSessionProvider(TestCoreServices.CreateReal()); // ReSharper disable once AccessToDisposedClosure Action a = () => sessionProvider.GetOrCreate(new Guid()); a.ShouldNotThrow(); sessionProvider.Dispose(); a.ShouldThrow <InvalidOperationException>(); }
public void Lifecycle() { var sessionProvider = new RSessionProvider(); // ReSharper disable once AccessToDisposedClosure Action a = () => sessionProvider.GetOrCreate(new Guid(), _brokerConnector); a.ShouldNotThrow(); sessionProvider.Dispose(); a.ShouldThrow <InvalidOperationException>(); }
public void Lifecycle() { var sessionProvider = new RSessionProvider(_services); // ReSharper disable once AccessToDisposedClosure Action a = () => sessionProvider.GetOrCreate(nameof(Lifecycle)); a.ShouldNotThrow(); sessionProvider.Dispose(); a.ShouldThrow <InvalidOperationException>(); }
public async Task RemoveBroker() { var sessionProvider = new RSessionProvider(_services); var session1 = sessionProvider.GetOrCreate(nameof(RemoveBroker) + 1); var session2 = sessionProvider.GetOrCreate(nameof(RemoveBroker) + 2); session2.RestartOnBrokerSwitch = true; await sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(RemoveBroker)).Should().BeCompletedAsync(); session1.HostStarted.Should().NotBeCompleted(); session2.HostStarted.Should().BeCompleted(); await session1.EnsureHostStartedAsync(new RHostStartupInfo(), null, 5000).Should().BeCompletedAsync(); await sessionProvider.RemoveBrokerAsync(); session1.IsHostRunning.Should().BeFalse(); session2.IsHostRunning.Should().BeFalse(); }
public async Task ConnectToRemote() { using (var sessionProvider = new RSessionProvider(_services)) { await _remoteBroker.ConnectAsync(sessionProvider); var session = sessionProvider.GetOrCreate(nameof(ConnectToRemote)); await session.EnsureHostStartedAsync(new RHostStartupInfo(), null, 5000); var evaluationResult = await session.EvaluateAsync <int>("1+2", REvaluationKind.Normal); evaluationResult.Should().Be(3); } }
public async Task SwitchBrokerWithCancellation(int timeout) { using (var sessionProvider = new RSessionProvider(_coreServices)) { var session = sessionProvider.GetOrCreate(nameof(SwitchBrokerWithCancellation)); await sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchBrokerWithCancellation)); await session.EnsureHostStartedAsync(new RHostStartupInfo(), null, 1000); var result = await sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchBrokerWithCancellation) + "1", cancellationToken : new CancellationTokenSource(timeout).Token); result.Should().BeFalse(); } }
public async Task SwitchWhileEnsureHostStartedAsyncFailed() { using (var sessionProvider = new RSessionProvider(_services)) { var session = sessionProvider.GetOrCreate(nameof(SwitchWhileEnsureHostStartedAsyncFailed)); session.RestartOnBrokerSwitch = true; var startTask = session.EnsureHostStartedAsync(new RHostStartupInfo(), null, 1000); await Task.Yield(); await sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchWhileEnsureHostStartedAsyncFailed)); startTask.Should().BeCanceled(); session.IsHostRunning.Should().BeTrue(); } }
public async Task SwitchWhileEnsureHostStartedAsyncFailed() { using (var sessionProvider = new RSessionProvider(TestCoreServices.CreateReal())) { var guid = new Guid(); var session = sessionProvider.GetOrCreate(guid); var startTask = session.EnsureHostStartedAsync(new RHostStartupInfo { Name = nameof(session) }, null, 1000); await Task.Yield(); await sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchWhileEnsureHostStartedAsyncFailed)); startTask.Should().BeCanceled(); session.IsHostRunning.Should().BeTrue(); } }
public async Task SwitchToTheSameBroker() { using (var sessionProvider = new RSessionProvider(_services)) { var session = sessionProvider.GetOrCreate(nameof(SwitchToTheSameBroker)); session.RestartOnBrokerSwitch = true; await sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchToTheSameBroker)); await session.EnsureHostStartedAsync(new RHostStartupInfo(), null, 1000); var switch1Task = sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchToTheSameBroker) + "1"); var switch2Task = sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchToTheSameBroker) + "1"); await ParallelTools.WhenAll(30000, switch1Task, switch2Task); switch1Task.Status.Should().Be(TaskStatus.RanToCompletion); switch2Task.Status.Should().Be(TaskStatus.RanToCompletion); } }
private async Task ExecuteInSession(string[] inputs, IRSessionCallback app) { using (var sessionProvider = new RSessionProvider(_services)) { await sessionProvider.TrySwitchBrokerAsync(nameof(IdeGraphicsDeviceTest)); var session = sessionProvider.GetOrCreate(_testMethod.FileSystemSafeName); await session.StartHostAsync(new RHostStartupInfo(), app, 50000); foreach (var input in inputs) { using (var interaction = await session.BeginInteractionAsync()) { await interaction.RespondAsync(input.EnsureLineBreak()); } } await session.StopHostAsync(); } }
private async Task ExecuteInSession(string[] inputs, IRSessionCallback app) { using (var sessionProvider = new RSessionProvider()) { var session = sessionProvider.GetOrCreate(Guid.NewGuid(), _brokerConnector); await session.StartHostAsync(new RHostStartupInfo { Name = _testMethod.Name }, app, 50000); foreach (var input in inputs) { using (var interaction = await session.BeginInteractionAsync()) { await interaction.RespondAsync(input + "\n"); } } await session.StopHostAsync(); } }
public async Task SwitchBroker_DisposeSession(int timeout, bool restartOnBrokerSwitch) { using (var sessionProvider = new RSessionProvider(_services)) { var session = sessionProvider.GetOrCreate(nameof(SwitchBroker_DisposeSession)); session.RestartOnBrokerSwitch = restartOnBrokerSwitch; await sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchBroker_DisposeSession)); await session.EnsureHostStartedAsync(new RHostStartupInfo(), null, 5000); var sessionDisposeTask = Task.Delay(timeout).ContinueWith(t => session.Dispose()); var result = await sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchBroker_DisposeSession) + "1"); await sessionDisposeTask; result.Should().BeTrue(); } }
public async Task SwitchBrokerWithCancellation(int timeout) { using (var sessionProvider = new RSessionProvider(_services)) { var session = sessionProvider.GetOrCreate(nameof(SwitchBrokerWithCancellation)); await sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchBrokerWithCancellation)); await session.EnsureHostStartedAsync(new RHostStartupInfo(), null, 1000); var stopwatch = new Stopwatch(); stopwatch.Start(); var result = await sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchBrokerWithCancellation) + "1", cancellationToken : new CancellationTokenSource(timeout).Token); stopwatch.Stop(); result.Should().Be(stopwatch.ElapsedMilliseconds < timeout); } }
public async Task ConnectWhenSwitching_SwitchFailed() { using (var sessionProvider = new RSessionProvider(_services)) { await sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(ConnectWhenSwitching_SwitchFailed)); var switchTask = sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(ConnectWhenSwitching_SwitchFailed) + "1", BrokerConnectionInfo.Create(null, "JHFFR", @"\\JHF\F\R")); await Task.Yield(); var session = sessionProvider.GetOrCreate(nameof(ConnectWhenSwitching_SwitchFailed)); var startHostTask = session.EnsureHostStartedAsync(new RHostStartupInfo(), null, 1000); await ParallelTools.WhenAll(30000, switchTask, startHostTask); startHostTask.Should().BeRanToCompletion(); switchTask.Should().BeRanToCompletion(); switchTask.Result.Should().BeFalse(); } }
public async Task SwitchMultipleSessions() { using (var sessionProvider = new RSessionProvider(_services)) { await sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchMultipleSessions)).Should().BeCompletedAsync(); var sessions = new IRSession[4]; for (var i = 0; i < sessions.Length; i++) { sessions[i] = sessionProvider.GetOrCreate(nameof(SwitchMultipleSessions) + i); sessions[i].RestartOnBrokerSwitch = true; } await ParallelTools.WhenAll(30000, sessions.Select((s, i) => s.EnsureHostStartedAsync(new RHostStartupInfo(), null, 30000)).ToArray()); await sessionProvider.TrySwitchBrokerAsync(nameof(RSessionProviderTest) + nameof(SwitchMultipleSessions) + "1").Should().BeCompletedAsync(); sessions.Should().OnlyContain(s => s.IsHostRunning); } }