From 69343c64b63e2ae675332df10a8ad786cbda7094 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 3 Jun 2018 18:01:27 +0300 Subject: Implemented RemoteRunner! --- Software/Visual_Studio/Tango.UnitTesting/Helper.cs | 9 +++ .../Tango.UnitTesting/RemoteRunner_TST.cs | 92 ++++++++++++++++++++++ .../Tango.UnitTesting/Tango.UnitTesting.csproj | 5 ++ 3 files changed, 106 insertions(+) create mode 100644 Software/Visual_Studio/Tango.UnitTesting/RemoteRunner_TST.cs (limited to 'Software/Visual_Studio/Tango.UnitTesting') diff --git a/Software/Visual_Studio/Tango.UnitTesting/Helper.cs b/Software/Visual_Studio/Tango.UnitTesting/Helper.cs index e09b17149..67252f914 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/Helper.cs +++ b/Software/Visual_Studio/Tango.UnitTesting/Helper.cs @@ -43,6 +43,15 @@ namespace Tango.UnitTesting return Path.GetFullPath(@"..\..\Build\Debug\Tango.MachineStudio.UI.exe"); } + /// + /// Gets the tango build path. + /// + /// + public static String GetBuildPath() + { + return Path.GetFullPath(@"..\..\Build\Debug"); + } + /// /// Gets the SQLite database file path in DB folder. /// diff --git a/Software/Visual_Studio/Tango.UnitTesting/RemoteRunner_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/RemoteRunner_TST.cs new file mode 100644 index 000000000..6e59dde8a --- /dev/null +++ b/Software/Visual_Studio/Tango.UnitTesting/RemoteRunner_TST.cs @@ -0,0 +1,92 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Tango.Transport; +using Tango.Transport.Transporters; +using Tango.Transport.Adapters; +using Tango.PMR.IO; +using Tango.PMR; +using Google.Protobuf; + +namespace Tango.UnitTesting +{ + [TestClass] + [TestCategory("Remote Runner")] + public class RemoteRunner_TST + { + [TestMethod] + public void Run_Remote_Runner_Connect_Upload_And_Execute_Process() + { + Process runner = Process.Start(Path.Combine(Helper.GetBuildPath(), "Tango.RemoteRunner.UI.exe")); + runner.WaitForInputIdle(); + + Thread.Sleep(2000); + + ITransportAdapter adapter = new TcpTransportAdapter("localhost", 9595); + ITransporter transporter = new BasicTransporter(adapter); + transporter.Connect().Wait(); + + Thread.Sleep(1000); + + String uploadFileName = "RemoteRunnerExeTest.zip"; + String executeFileName = "RemoteRunnerExeTest.exe"; + + FileInfo exeFile = new FileInfo(Helper.GetResourcePath(uploadFileName)); + + var uploadResponse = transporter.SendRequest(new FileUploadRequest() + { + FileName = uploadFileName, + Length = exeFile.Length, + }).Result.Message; + + int currentFilePosition = 0; + + do + { + using (FileStream fs = new FileStream(exeFile.FullName, FileMode.Open)) + { + fs.Position = currentFilePosition; + + FileChunkUploadRequest chunkRequest = new FileChunkUploadRequest(); + chunkRequest.UploadID = uploadResponse.UploadID; + + long remaining = exeFile.Length - currentFilePosition; + + byte[] buffer = new byte[uploadResponse.MaxChunkLength > remaining ? uploadResponse.MaxChunkLength : remaining]; + fs.Read(buffer, 0, buffer.Length); + chunkRequest.Buffer = ByteString.CopyFrom(buffer); + + transporter.SendRequest(chunkRequest).Wait(); + + currentFilePosition += buffer.Length; + } + + } while (currentFilePosition < exeFile.Length); + + Thread.Sleep(1000); + + var response = transporter.SendRequest(new ExecuteProcessRequest() + { + UploadID = uploadResponse.UploadID, + FileName = executeFileName, + }, TimeSpan.FromSeconds(30)).Result.Message; + + Thread.Sleep(5000); + + transporter.SendRequest(new KillProcessRequest() + { + ProcessID = response.ProcessID, + }).Wait(); + + transporter.Disconnect().Wait(); + + runner.Kill(); + } + } +} diff --git a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj index b01b6374b..9fbcc4d09 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj +++ b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj @@ -90,6 +90,7 @@ + @@ -168,6 +169,10 @@ {998f8471-dc1b-41b6-9d96-354e1b4e7a32} Tango.TFS + + {74e700b0-1156-4126-be40-ee450d3c3026} + Tango.Transport + {ebb7cb9f-6af2-456b-a5dd-1b136b605d90} Tango.DBObservablesGenerator.CLI -- cgit v1.3.1