diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-06-03 18:01:27 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-06-03 18:01:27 +0300 |
| commit | 69343c64b63e2ae675332df10a8ad786cbda7094 (patch) | |
| tree | 4d6510feaeeba2adad0e2257586ffe1582b2831d /Software/Visual_Studio/Tango.UnitTesting/RemoteRunner_TST.cs | |
| parent | 34b3f33ec9ccb682c430b3c9e206507d0a396e1c (diff) | |
| download | Tango-69343c64b63e2ae675332df10a8ad786cbda7094.tar.gz Tango-69343c64b63e2ae675332df10a8ad786cbda7094.zip | |
Implemented RemoteRunner!
Diffstat (limited to 'Software/Visual_Studio/Tango.UnitTesting/RemoteRunner_TST.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.UnitTesting/RemoteRunner_TST.cs | 92 |
1 files changed, 92 insertions, 0 deletions
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<FileUploadRequest, FileUploadResponse>(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<FileChunkUploadRequest, FileChunkUploadResponse>(chunkRequest).Wait(); + + currentFilePosition += buffer.Length; + } + + } while (currentFilePosition < exeFile.Length); + + Thread.Sleep(1000); + + var response = transporter.SendRequest<ExecuteProcessRequest, ExecuteProcessResponse>(new ExecuteProcessRequest() + { + UploadID = uploadResponse.UploadID, + FileName = executeFileName, + }, TimeSpan.FromSeconds(30)).Result.Message; + + Thread.Sleep(5000); + + transporter.SendRequest<KillProcessRequest, KillProcessResponse>(new KillProcessRequest() + { + ProcessID = response.ProcessID, + }).Wait(); + + transporter.Disconnect().Wait(); + + runner.Kill(); + } + } +} |
