Skip to content

Commit 02ef655

Browse files
committed
Enables console output for release tests.
1 parent 61401a8 commit 02ef655

File tree

14 files changed

+138
-65
lines changed

14 files changed

+138
-65
lines changed

Framework/Logging/BaseLog.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ public interface ILog
77
void Log(string message);
88
void Debug(string message = "", int skipFrames = 0);
99
void Error(string message);
10+
void Raw(string message);
1011
void AddStringReplace(string from, string to);
1112
LogFile CreateSubfile(string addName, string ext = "log");
13+
string GetFullName();
1214
}
1315

1416
public abstract class BaseLog : ILog
@@ -28,7 +30,8 @@ public BaseLog()
2830
}
2931

3032
protected bool IsDebug { get; private set; }
31-
protected abstract string GetFullName();
33+
34+
public abstract string GetFullName();
3235

3336
public LogFile LogFile
3437
{
@@ -60,6 +63,11 @@ public virtual void Error(string message)
6063
Log(msg);
6164
}
6265

66+
public void Raw(string message)
67+
{
68+
LogFile.WriteRaw(message);
69+
}
70+
6371
public virtual void AddStringReplace(string from, string to)
6472
{
6573
if (string.IsNullOrWhiteSpace(from)) return;

Framework/Logging/ConsoleLog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
public class ConsoleLog : BaseLog
44
{
5-
protected override string GetFullName()
5+
public override string GetFullName()
66
{
77
return "CONSOLE";
88
}

Framework/Logging/FileLog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public FileLog(string fullFilename)
99

1010
public string FullFilename { get; }
1111

12-
protected override string GetFullName()
12+
public override string GetFullName()
1313
{
1414
return FullFilename;
1515
}

Framework/Logging/LogPrefixer.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public LogPrefixer(ILog backingLog, string prefix)
1717

1818
public string Prefix { get; set; } = string.Empty;
1919

20-
2120
public LogFile CreateSubfile(string addName, string ext = "log")
2221
{
2322
return backingLog.CreateSubfile(addName, ext);
@@ -42,5 +41,15 @@ public void AddStringReplace(string from, string to)
4241
{
4342
backingLog.AddStringReplace(from, to);
4443
}
44+
45+
public void Raw(string message)
46+
{
47+
backingLog.Raw(message);
48+
}
49+
50+
public string GetFullName()
51+
{
52+
return backingLog.GetFullName();
53+
}
4554
}
4655
}

Framework/Logging/LogSplitter.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,21 @@ public void Error(string message)
2929
OnAll(l => l.Error(message));
3030
}
3131

32+
public string GetFullName()
33+
{
34+
return targetLogs.First().GetFullName();
35+
}
36+
3237
public void Log(string message)
3338
{
3439
OnAll(l => l.Log(message));
3540
}
3641

42+
public void Raw(string message)
43+
{
44+
OnAll(l => l.Raw(message));
45+
}
46+
3747
private void OnAll(Action<ILog> action)
3848
{
3949
foreach (var t in targetLogs) action(t);

Framework/Logging/NullLog.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
{
33
public class NullLog : BaseLog
44
{
5-
public string FullFilename { get; set; } = "NULL";
6-
7-
protected override string GetFullName()
5+
public override string GetFullName()
86
{
9-
return FullFilename;
7+
return "NULL";
108
}
119

1210
public override void Log(string message)

Tests/CodexContinuousTests/ContinuousTestRunner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void Run()
2727
var startTime = DateTime.UtcNow;
2828

2929
var overviewLog = new LogSplitter(
30-
new FixtureLog(logConfig, startTime, config.CodexDeployment.Id, "Overview"),
30+
FixtureLog.Create(logConfig, startTime, config.CodexDeployment.Id, "Overview"),
3131
new ConsoleLog()
3232
);
3333
var statusLog = new StatusLog(logConfig, startTime, "continuous-tests", config.CodexDeployment.Id,

Tests/CodexContinuousTests/SingleTestRun.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public SingleTestRun(EntryPointFactory entryPointFactory,
3737
this.handle = handle;
3838
this.cancelToken = cancelToken;
3939
testName = handle.Test.GetType().Name;
40-
fixtureLog = new FixtureLog(new LogConfig(config.LogPath), DateTime.UtcNow, deployId, testName);
40+
fixtureLog = FixtureLog.Create(new LogConfig(config.LogPath), DateTime.UtcNow, deployId, testName);
4141
entryPoint = entryPointFactory.CreateEntryPoint(config.KubeConfigFile, config.DataPath,
4242
config.CodexDeployment.Metadata.KubeNamespace, fixtureLog);
4343
ApplyLogReplacements(fixtureLog, startupChecker);
@@ -81,17 +81,11 @@ private void RunTest(Action<bool> resultHandler)
8181
OverviewLog($" > Test passed. ({Time.FormatDuration(duration)})");
8282
UpdateStatusLogPassed(testStart, duration);
8383

84-
if (!config.KeepPassedTestLogs)
85-
{
86-
fixtureLog.Delete();
87-
}
88-
8984
resultHandler(true);
9085
}
9186
catch (Exception ex)
9287
{
9388
fixtureLog.Error("Test run failed with exception: " + ex);
94-
fixtureLog.MarkAsFailed();
9589
UpdateStatusLogFailed(testStart, duration, ex.ToString());
9690

9791
DownloadContainerLogs(testStart);

Tests/CodexContinuousTests/StartupChecker.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public StartupChecker(EntryPoint entryPoint, Configuration config, CancellationT
2222

2323
public void Check()
2424
{
25-
var log = new FixtureLog(new LogConfig(config.LogPath), DateTime.UtcNow, config.CodexDeployment.Id,
25+
var log = FixtureLog.Create(new LogConfig(config.LogPath), DateTime.UtcNow, config.CodexDeployment.Id,
2626
"StartupChecks");
2727
log.Log("Starting continuous test run...");
2828
IncludeDeploymentConfiguration(log);
@@ -90,7 +90,7 @@ private void PreflightCheck(Configuration config)
9090
}
9191
}
9292

93-
private void CheckCodexNodes(BaseLog log, Configuration config)
93+
private void CheckCodexNodes(ILog log, Configuration config)
9494
{
9595
throw new NotImplementedException();
9696

Tests/DistTestCore/DistTest.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public DistTest()
3333

3434
var logConfig = configuration.GetLogConfig();
3535
var startTime = DateTime.UtcNow;
36-
fixtureLog = new FixtureLog(logConfig, startTime, deployId);
36+
fixtureLog = FixtureLog.Create(logConfig, startTime, deployId);
3737
statusLog = new StatusLog(logConfig, startTime, "dist-tests", deployId);
3838

3939
globalEntryPoint = new EntryPoint(fixtureLog, configuration.GetK8sConfiguration(new DefaultK8sTimeSet(), TestNamespacePrefix), configuration.GetFileManagerFolder());
@@ -44,7 +44,7 @@ public DistTest()
4444
[OneTimeSetUp]
4545
public void GlobalSetup()
4646
{
47-
fixtureLog.Log($"Distributed Tests are starting...");
47+
fixtureLog.Log($"Starting...");
4848
globalEntryPoint.Announce();
4949

5050
// Previous test run may have been interrupted.
@@ -87,7 +87,15 @@ public void SetUpDistTest()
8787
}
8888
else
8989
{
90-
CreateNewTestLifecycle();
90+
try
91+
{
92+
CreateNewTestLifecycle();
93+
}
94+
catch (Exception ex)
95+
{
96+
fixtureLog.Error("Setup failed: " + ex);
97+
GlobalTestFailure.HasFailed = true;
98+
}
9199
}
92100
}
93101

@@ -236,11 +244,6 @@ private void WriteEndTestLog(TestLog log)
236244
Log(result.Message);
237245
Log($"{result.StackTrace}");
238246
}
239-
240-
if (result.Outcome.Status == TestStatus.Failed)
241-
{
242-
log.MarkAsFailed();
243-
}
244247
}
245248

246249
private IWebCallTimeSet GetWebCallTimeSet()
@@ -296,11 +299,6 @@ protected T[] GetCurrentTestMethodAttribute<T>() where T : PropertyAttribute
296299
private void IncludeLogsOnTestFailure(TestLifecycle lifecycle)
297300
{
298301
var testStatus = TestContext.CurrentContext.Result.Outcome.Status;
299-
if (testStatus == TestStatus.Failed)
300-
{
301-
fixtureLog.MarkAsFailed();
302-
}
303-
304302
if (ShouldDownloadAllLogs(testStatus))
305303
{
306304
lifecycle.Log.Log("Downloading all container logs...");

Tests/DistTestCore/Logs/BaseTestLog.cs

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,83 @@
22

33
namespace DistTestCore.Logs
44
{
5-
public abstract class BaseTestLog : BaseLog
5+
public abstract class BaseTestLog : ILog
66
{
7-
private bool hasFailed;
8-
private readonly string deployId;
7+
private readonly ILog backingLog;
98

10-
protected BaseTestLog(string deployId)
9+
protected BaseTestLog(ILog backingLog, string deployId)
1110
{
12-
this.deployId = deployId;
11+
this.backingLog = backingLog;
12+
13+
DeployId = deployId;
14+
}
15+
16+
public string DeployId { get; }
17+
18+
public void AddStringReplace(string from, string to)
19+
{
20+
backingLog.AddStringReplace(from, to);
21+
}
22+
23+
public LogFile CreateSubfile(string addName, string ext = "log")
24+
{
25+
return backingLog.CreateSubfile(addName, ext);
26+
}
27+
28+
public void Debug(string message = "", int skipFrames = 0)
29+
{
30+
backingLog.Debug(message, skipFrames);
31+
}
32+
33+
public void Error(string message)
34+
{
35+
backingLog.Error(message);
36+
}
37+
38+
public string GetFullName()
39+
{
40+
return backingLog.GetFullName();
41+
}
42+
43+
public void Log(string message)
44+
{
45+
backingLog.Log(message);
46+
}
47+
48+
public void Raw(string message)
49+
{
50+
backingLog.Raw(message);
1351
}
1452

1553
public void WriteLogTag()
1654
{
1755
var category = NameUtils.GetCategoryName();
1856
var name = NameUtils.GetTestMethodName();
19-
LogFile.WriteRaw($"{deployId} {category} {name}");
57+
backingLog.Raw($"{DeployId} {category} {name}");
2058
}
2159

22-
public void MarkAsFailed()
60+
protected static ILog CreateMainLog(string fullName, string name)
2361
{
24-
if (hasFailed) return;
25-
hasFailed = true;
62+
ILog log = new FileLog(fullName);
63+
log = ApplyConsoleOutput(log);
64+
return log;
65+
}
66+
67+
private static ILog ApplyConsoleOutput(ILog log)
68+
{
69+
// If we're running as a release test, we'll split the log output
70+
// to the console as well.
71+
72+
var testType = Environment.GetEnvironmentVariable("TEST_TYPE");
73+
if (string.IsNullOrEmpty(testType) || testType.ToLowerInvariant() != "release-tests")
74+
{
75+
return log;
76+
}
77+
78+
return new LogSplitter(
79+
log,
80+
new ConsoleLog()
81+
);
2682
}
2783
}
2884
}

Tests/DistTestCore/Logs/FixtureLog.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,26 @@ namespace DistTestCore.Logs
44
{
55
public class FixtureLog : BaseTestLog
66
{
7-
private readonly string fullName;
7+
private readonly ILog backingLog;
88
private readonly string deployId;
99

10-
public FixtureLog(LogConfig config, DateTime start, string deployId, string name = "") : base(deployId)
10+
public FixtureLog(ILog backingLog, string deployId)
11+
: base(backingLog, deployId)
1112
{
13+
this.backingLog = backingLog;
1214
this.deployId = deployId;
13-
fullName = NameUtils.GetFixtureFullName(config, start, name);
1415
}
1516

1617
public TestLog CreateTestLog(string name = "")
1718
{
18-
return new TestLog(fullName, deployId, name);
19+
return TestLog.Create(this, name);
1920
}
2021

21-
public void DeleteFolder()
22+
public static FixtureLog Create(LogConfig config, DateTime start, string deployId, string name = "")
2223
{
23-
Directory.Delete(fullName, true);
24-
}
25-
26-
protected override string GetFullName()
27-
{
28-
return fullName;
24+
var fullName = NameUtils.GetFixtureFullName(config, start, name);
25+
var log = CreateMainLog(fullName, name);
26+
return new FixtureLog(log, deployId);
2927
}
3028
}
31-
}
29+
}

Tests/DistTestCore/Logs/TestLog.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
namespace DistTestCore.Logs
1+
using Logging;
2+
using System.Xml.Linq;
3+
4+
namespace DistTestCore.Logs
25
{
36
public class TestLog : BaseTestLog
47
{
5-
private readonly string fullName;
6-
7-
public TestLog(string folder, string deployId, string name = "") : base(deployId)
8+
public TestLog(ILog backingLog, string methodName, string deployId, string name = "")
9+
: base(backingLog, deployId)
810
{
9-
var methodName = NameUtils.GetTestMethodName(name);
10-
fullName = Path.Combine(folder, methodName);
11-
12-
Log($"*** Begin: {methodName}");
11+
backingLog.Log($"*** Begin: {methodName}");
1312
}
1413

15-
protected override string GetFullName()
14+
public static TestLog Create(FixtureLog parentLog, string name = "")
1615
{
17-
return fullName;
16+
var methodName = NameUtils.GetTestMethodName(name);
17+
var fullName = Path.Combine(parentLog.GetFullName(), methodName);
18+
var backingLog = CreateMainLog(fullName, name);
19+
return new TestLog(backingLog, methodName, parentLog.DeployId);
1820
}
1921
}
2022
}

0 commit comments

Comments
 (0)