forked from hpsa/hpe-application-automation-tools-plugin
-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
F#2051006 Controller Service - Jenkins plugin integration #628
Draft
tinccristian
wants to merge
10
commits into
jenkinsci:latest
Choose a base branch
from
tinccristian:service-plugin
base: latest
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6be2fc0
Add Service
eef4232
Code Cleanup
af126c7
Add setResultsDirectory command support
04c0fb3
Merge remote-tracking branch 'upstream/latest' into service-plugin
tinccristian ccf7f1e
Revert to dotnet 4.0
tinccristian 7f9d00c
separate service classes
tinccristian 237c92d
Update RunFromService.java
tinccristian 0fbc649
Merge remote-tracking branch 'upstream/latest' into service-plugin
tinccristian 89d06c5
Update ServiceTestRunner.cs
tinccristian dc3dd6e
Update ServiceTestRunner.cs
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Threading; | ||
|
||
namespace HpToolsLauncher.TestRunners | ||
{ | ||
public class ServiceTestRunner | ||
{ | ||
// | ||
public string binPath = Environment.ExpandEnvironmentVariables("%LR_PATH%bin"); | ||
public string[] processesToKill = new string[] { "wlrun", "lrun_svc", "CmdServiceClient" }; | ||
public int _timeout; | ||
|
||
public bool RunServiceTest(string testPath, string resultsDirectory, int timeout) | ||
{ | ||
_timeout = timeout * 1000; | ||
Cleanup(processesToKill); | ||
LogMessage("Cleanup complete."); | ||
|
||
//Start lrun_svc.exe and CmdServiceClient.exe | ||
StartLrunSvc(); | ||
LogMessage("lrun_svc.exe is running"); | ||
Process client = StartClient(); | ||
LogMessage("CmdServiceClient.exe is running"); | ||
|
||
//Set the load test data to the given .lrs | ||
string command = "setLoadTestData " + testPath; | ||
Write(client, command); | ||
LogMessage("Command given:",command); | ||
|
||
string result = Read(client); | ||
LogMessage("Client response:", result); | ||
if ((result.Contains("failed") || (result.Contains("empty")))) | ||
{ | ||
Cleanup(processesToKill); | ||
return false; | ||
} | ||
|
||
|
||
//Set the results folder directory | ||
string command1 ="setResultsDirectory " + resultsDirectory; | ||
Write(client, command1); | ||
LogMessage("Command given:", command1); | ||
|
||
result = Read(client); | ||
LogMessage("Client response:",result); | ||
if ((result.Contains("failed") || (result.Contains("empty")))) | ||
{ | ||
Cleanup(processesToKill); | ||
return false; | ||
} | ||
|
||
//Start the load test | ||
Write(client,"startLoadTest"); | ||
LogMessage("Command given: startLoadTest"); | ||
|
||
result = Read(client); | ||
LogMessage("Client response:",result); | ||
if (result.Contains("failed")) | ||
{ | ||
Cleanup(processesToKill); | ||
return false; | ||
} | ||
LogMessage("The test has started, waiting for the test to end."); | ||
Stopwatch stopWatch = new Stopwatch(); | ||
stopWatch.Start(); | ||
var startTime= DateTime.Now; | ||
|
||
//Get the result | ||
result = ""; | ||
while (!result.Contains("Ended")) //wait for the test to end | ||
{ | ||
Write(client, "getServiceState"); //ready, collating, running, ended | ||
result = Read(client); | ||
if ((result.Contains("failed") || (result.Contains("empty")))) | ||
{ | ||
LogMessage(result); | ||
Cleanup(processesToKill); | ||
return false; | ||
} | ||
Thread.Sleep(1); | ||
} | ||
|
||
stopWatch.Stop(); | ||
TimeSpan ts = stopWatch.Elapsed; | ||
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", | ||
ts.Hours, ts.Minutes, ts.Seconds, | ||
ts.Milliseconds / 10); | ||
LogMessage("Test completed in", elapsedTime); | ||
Dispose(client); | ||
Cleanup(processesToKill); | ||
return true; | ||
} | ||
|
||
#region Process utilities | ||
public void StartLrunSvc() | ||
{ | ||
LogMessage("Starting lrun_svc.exe..."); | ||
var startInfo = new System.Diagnostics.ProcessStartInfo | ||
{ | ||
WorkingDirectory = binPath, | ||
FileName = "lrun_svc.exe", | ||
}; | ||
var proc = new Process | ||
{ | ||
StartInfo = startInfo | ||
}; | ||
proc.Start(); | ||
System.Threading.Thread.Sleep(5000); | ||
} | ||
|
||
public Process StartClient() | ||
{ | ||
var startInfo = new System.Diagnostics.ProcessStartInfo | ||
{ | ||
FileName = binPath + @"\CmdServiceClient.exe", | ||
RedirectStandardInput = true, | ||
RedirectStandardOutput = true, | ||
UseShellExecute = false | ||
}; | ||
|
||
var proc = new Process | ||
{ | ||
StartInfo = startInfo | ||
}; | ||
proc.Start(); | ||
return proc; | ||
} | ||
|
||
public void Cleanup(string[] processes) | ||
{ | ||
foreach (string process in processes) | ||
{ | ||
Process[] workers = Process.GetProcessesByName(process); | ||
foreach (Process worker in workers) | ||
{ | ||
try | ||
{ | ||
worker.Kill(); | ||
worker.WaitForExit(); | ||
worker.Dispose(); | ||
} | ||
catch (UnauthorizedAccessException) | ||
{ | ||
continue; | ||
} | ||
|
||
} | ||
} | ||
|
||
} | ||
|
||
public void LogMessage(string message) | ||
{ | ||
Console.WriteLine("[{0}] {1}", DateTime.Now.ToString("h:mm:ss tt"), message); | ||
} | ||
|
||
public void LogMessage(string message, string extraInfo) | ||
{ | ||
Console.WriteLine("[{0}] {1} {2}", DateTime.Now.ToString("h:mm:ss tt"), message, extraInfo); | ||
} | ||
#endregion | ||
|
||
#region Client communication | ||
public void Write(Process client, string command) | ||
{ | ||
StreamWriter writer = client.StandardInput; | ||
writer.WriteLine(command); | ||
writer.Flush(); | ||
} | ||
public void Write(Process client, string command, int timeout) | ||
{ | ||
StreamWriter writer = client.StandardInput; | ||
writer.WriteLine(command); | ||
//System.Threading.Thread.Sleep(timeout); | ||
writer.Flush(); | ||
} | ||
public string ReadLine(Process client) | ||
{ | ||
|
||
StreamReader reader = client.StandardOutput; | ||
string result = ""; | ||
do | ||
{ | ||
int output = reader.Read(); | ||
result += (char)output; | ||
} | ||
while (reader.Peek() > -1); | ||
reader.DiscardBufferedData(); | ||
return result; | ||
} | ||
public void Dispose(Process client) | ||
{ | ||
client.StandardInput.Close(); | ||
client.StandardOutput.Close(); | ||
client.Dispose(); | ||
} | ||
public string Read(Process client) | ||
{ | ||
string result = ReadLine(client); | ||
while (result.Length < 3) | ||
{ | ||
result =ReadLine(client); | ||
System.Threading.Thread.Sleep(5); | ||
} | ||
return result; | ||
} | ||
} | ||
#endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid too many
return
statements within this method.