aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.UnitTesting
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-06-03 18:01:27 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-06-03 18:01:27 +0300
commit69343c64b63e2ae675332df10a8ad786cbda7094 (patch)
tree4d6510feaeeba2adad0e2257586ffe1582b2831d /Software/Visual_Studio/Tango.UnitTesting
parent34b3f33ec9ccb682c430b3c9e206507d0a396e1c (diff)
downloadTango-69343c64b63e2ae675332df10a8ad786cbda7094.tar.gz
Tango-69343c64b63e2ae675332df10a8ad786cbda7094.zip
Implemented RemoteRunner!
Diffstat (limited to 'Software/Visual_Studio/Tango.UnitTesting')
-rw-r--r--Software/Visual_Studio/Tango.UnitTesting/Helper.cs9
-rw-r--r--Software/Visual_Studio/Tango.UnitTesting/RemoteRunner_TST.cs92
-rw-r--r--Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj5
3 files changed, 106 insertions, 0 deletions
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
@@ -44,6 +44,15 @@ namespace Tango.UnitTesting
}
/// <summary>
+ /// Gets the tango build path.
+ /// </summary>
+ /// <returns></returns>
+ public static String GetBuildPath()
+ {
+ return Path.GetFullPath(@"..\..\Build\Debug");
+ }
+
+ /// <summary>
/// Gets the SQLite database file path in DB folder.
/// </summary>
/// <returns></returns>
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();
+ }
+ }
+}
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 @@
<Compile Include="DependencyInjection_TST.cs" />
<Compile Include="Logging_TST.cs" />
<Compile Include="MachineStudio_TST.cs" />
+ <Compile Include="RemoteRunner_TST.cs" />
<Compile Include="Temporary_TST.cs" />
<Compile Include="TFS_TST.cs" />
<Compile Include="Outlook_TST.cs" />
@@ -168,6 +169,10 @@
<Project>{998f8471-dc1b-41b6-9d96-354e1b4e7a32}</Project>
<Name>Tango.TFS</Name>
</ProjectReference>
+ <ProjectReference Include="..\Tango.Transport\Tango.Transport.csproj">
+ <Project>{74e700b0-1156-4126-be40-ee450d3c3026}</Project>
+ <Name>Tango.Transport</Name>
+ </ProjectReference>
<ProjectReference Include="..\Utilities\Tango.DBObservablesGenerator.CLI\Tango.DBObservablesGenerator.CLI.csproj">
<Project>{ebb7cb9f-6af2-456b-a5dd-1b136b605d90}</Project>
<Name>Tango.DBObservablesGenerator.CLI</Name>