Skip to content
This repository has been archived by the owner on May 24, 2018. It is now read-only.

Commit

Permalink
Add more tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
jinxuunity committed Jul 17, 2017
1 parent 36aa7be commit 8f1fb6e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,29 @@ public class IntegrationTestsBase

protected void TestLog(string msg, ILogger logger, string level = "Information")
{
switch (level)
if (logger != null)
{
case "Information":
logger.Information(msg);
break;
case "Warning":
logger.Warning(msg);
break;
case "Error":
logger.Error(msg);
break;
default:
logger.Information(msg);
break;
switch (level)
{
case "Information":
logger.Information(msg);
break;
case "Warning":
logger.Warning(msg);
break;
case "Error":
logger.Error(msg);
break;
default:
logger.Information(msg);
break;
}
Trace.WriteLine(msg);
}
else
{
Trace.WriteLine("Logger is null, nothing logged");
}
Trace.WriteLine(msg);
}

protected string SetupLogFileName(string testcasename, string folder = "")
Expand Down Expand Up @@ -156,7 +163,8 @@ protected void WriteTraceToFile(TextWriterTraceListener myTextListener)
public void WaitPendingBuildRequestListEmpty(KatanaClient client,
string builder,
int t = 5,
List<string> revisions = null)
List<string> revisions = null,
ILogger logger = null)
{
int cnt = 0;
var response = client.GetPendingBuilds(builder);
Expand All @@ -170,6 +178,7 @@ protected void WriteTraceToFile(TextWriterTraceListener myTextListener)
foreach (var content in contents)
{
var build_revision = content["source"]["revision_short"].ToString();
TestLog($"Found build revision {build_revision} on {builder}", _logger);
if (revisions.Contains(build_revision))
{
matchfound = true;
Expand Down Expand Up @@ -206,20 +215,23 @@ public async Task FreeAllSlavesOfABuilder(KatanaClient client, string builder)
// risk: maybe there are multiple build on a slave, need check how to do that.
}

protected async Task StopRunningBuildsOnAllSlave(KatanaClient client, JObject slavearray)
protected async Task StopRunningBuildsOnAllSlave(KatanaClient client, JObject slavearray, ILogger logger = null)
{
foreach (var kvp in slavearray)
{
string slavename = kvp.Key;
JObject slave = (JObject)kvp.Value;
JArray runningBuilds = (JArray)slave["runningBuilds"];
if (runningBuilds != null)
{
if (runningBuilds.Count() > 0)
{
TestLog($"Found {runningBuilds.Count()} builds are running on {slavename}.", logger);
foreach (var build in runningBuilds)
{
string buildurl = build["builder_url"].ToString();
string buildnr = build["number"].ToString();
TestLog($"Stop build number {buildnr} on {slavename}", logger);
buildurl.Replace("?", $"/builds/{buildnr}/stop?");
await client.StopBuild(buildurl);
}
Expand All @@ -228,15 +240,17 @@ protected async Task StopRunningBuildsOnAllSlave(KatanaClient client, JObject sl
}
}


/// <summary>
/// Check the pending build request list, If there is a pending builds, stop the running build on the builder.
/// </summary>
/// <param name="client"></param>
/// <param name="project"></param>
/// <param name="builder"></param>
/// <param name="branch"></param>
public async Task StopCurrentBuildsIfPending(KatanaClient client, string project, string builder, string branch)
public async Task StopCurrentBuildsIfPending(KatanaClient client,
string project, string builder, string branch,
ILogger logger = null)
{
var response = client.GetPendingBuilds(builder);
string response_string = response.Result.Content.ReadAsStringAsync().Result;
Expand All @@ -247,6 +261,7 @@ public async Task StopCurrentBuildsIfPending(KatanaClient client, string project
foreach (var build in resp["currentBuilds"])
{
string _nr = build["number"].ToString();
TestLog($"Stop builder number {_nr} on builder {builder}", logger);
await client.StopBuild(project, builder, _nr, branch);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public ReliabilityTest(ITestOutputHelper output)
var branch = katanabuilder.Branch;
Assert.True(revision_list.Count >= 5, "Test need at least 5 revision string");
TestLog($"Read parameter project : {project}, builder: {builder}, branch: {branch}", _logger);
bool isWaiting = false;
bool isWaiting = false;
await FreeAllSlavesOfABuilder(client, builder);
#endregion

#region action
Expand Down Expand Up @@ -349,8 +350,8 @@ public async Task StopBuildsOnMultipleBuilder(List<KatanaBuild> katanabuilds, in

string _baseAddress = settings["BaseAddress"].ToString();
client.SetBaseAddress(_baseAddress);
TestLog($"Set base address {_baseAddress}", _logger);
TestLog($"Set base address {_baseAddress}", _logger);

bool isWaiting = false;
#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public async Task UseSpecifiedSlaveTest(KatanaBuilder katanabuilder,string revis
bool isPengingBuild = true;
while (isPengingBuild)
{
await StopCurrentBuildsIfPending(client, project, builder, branch);
await StopCurrentBuildsIfPending(client, project, builder, branch, _logger);
var response = client.GetPendingBuilds(builder);
JArray contents = JArray.Parse(response.Result.Content.ReadAsStringAsync().Result);
if (contents.Count < 1)
Expand Down

0 comments on commit 8f1fb6e

Please sign in to comment.