diff --git a/ProjectPlugins/CodexPlugin/OverwatchSupport/CodexTranscriptWriter.cs b/ProjectPlugins/CodexPlugin/OverwatchSupport/CodexTranscriptWriter.cs new file mode 100644 index 00000000..4927e9b2 --- /dev/null +++ b/ProjectPlugins/CodexPlugin/OverwatchSupport/CodexTranscriptWriter.cs @@ -0,0 +1,20 @@ +using Core; +using OverwatchTranscript; + +namespace CodexPlugin.OverwatchSupport +{ + public class CodexTranscriptWriter + { + private readonly ITranscriptWriter transcriptWriter; + + public CodexTranscriptWriter(ITranscriptWriter transcriptWriter) + { + this.transcriptWriter = transcriptWriter; + } + + public void ProcessLogs(IDownloadedLog[] downloadedLogs) + { + throw new NotImplementedException(); + } + } +} diff --git a/ProjectPlugins/CodexPlugin/OverwatchSupport/ModelExtensions.cs b/ProjectPlugins/CodexPlugin/OverwatchSupport/ModelExtensions.cs index 7b3bd638..aae8384f 100644 --- a/ProjectPlugins/CodexPlugin/OverwatchSupport/ModelExtensions.cs +++ b/ProjectPlugins/CodexPlugin/OverwatchSupport/ModelExtensions.cs @@ -1,17 +1,5 @@ namespace OverwatchTranscript { - [Serializable] - public partial class OverwatchHeader - { - public OverwatchCodexHeader? CodexHeader { get; set; } - } - - [Serializable] - public partial class OverwatchEvent - { - public OverwatchCodexEvent? CodexEvent { get; set; } - } - [Serializable] public class OverwatchCodexHeader { @@ -21,6 +9,7 @@ [Serializable] public class OverwatchCodexEvent { + public ScenarioFinishedEvent? ScenarioFinished { get; set; } public NodeStartedEvent? NodeStarted { get; set; } public NodeStoppedEvent? NodeStopped { get; set; } public FileUploadedEvent? FileUploaded { get; set; } @@ -30,6 +19,13 @@ #region Scenario Generated Events + [Serializable] + public class ScenarioFinishedEvent + { + public bool Success { get; set; } + public string Result { get; set; } = string.Empty; + } + [Serializable] public class NodeStartedEvent { diff --git a/Tests/CodexTests/CodexDistTest.cs b/Tests/CodexTests/CodexDistTest.cs index e62627ff..bd4fcacb 100644 --- a/Tests/CodexTests/CodexDistTest.cs +++ b/Tests/CodexTests/CodexDistTest.cs @@ -1,6 +1,7 @@ using CodexContractsPlugin; using CodexNetDeployer; using CodexPlugin; +using CodexPlugin.OverwatchSupport; using CodexTests.Helpers; using Core; using DistTestCore; @@ -9,11 +10,15 @@ using DistTestCore.Logs; using MetricsPlugin; using Newtonsoft.Json; using NUnit.Framework.Constraints; +using OverwatchTranscript; namespace CodexTests { public class CodexDistTest : DistTest { + private const bool enableOverwatchTranscript = true; + private static readonly Dictionary writers = new Dictionary(); + public CodexDistTest() { ProjectPlugin.Load(); @@ -29,6 +34,25 @@ namespace CodexTests localBuilder.Build(); } + protected override void LifecycleStart(TestLifecycle lifecycle) + { + base.LifecycleStart(lifecycle); + if (!enableOverwatchTranscript) return; + + writers.Add(lifecycle, new CodexTranscriptWriter(Transcript.NewWriter())); + } + + protected override void LifecycleStop(TestLifecycle lifecycle) + { + base.LifecycleStop(lifecycle); + if (!enableOverwatchTranscript) return; + + var writer = writers[lifecycle]; + writers.Remove(lifecycle); + + writer.ProcessLogs(lifecycle.DownloadAllLogs()); + } + public ICodexNode StartCodex() { return StartCodex(s => { }); @@ -50,6 +74,11 @@ namespace CodexTests { setup(s); OnCodexSetup(s); + + if (enableOverwatchTranscript) + { + s.WithTranscriptWriter(writers[Get()]); + } }); return group; diff --git a/Tests/DistTestCore/TestLifecycle.cs b/Tests/DistTestCore/TestLifecycle.cs index 568eae44..b67b4099 100644 --- a/Tests/DistTestCore/TestLifecycle.cs +++ b/Tests/DistTestCore/TestLifecycle.cs @@ -98,21 +98,29 @@ namespace DistTestCore } } - public void DownloadAllLogs() + private IDownloadedLog[] allLogs = Array.Empty(); + + public IDownloadedLog[] DownloadAllLogs() { + if (allLogs.Any()) return allLogs; + try { + var result = new List(); foreach (var rc in runningContainers) { foreach (var c in rc.Containers) { - CoreInterface.DownloadLog(c); + result.Add(CoreInterface.DownloadLog(c)); } } + allLogs = result.ToArray(); + return allLogs; } catch (Exception ex) { Log.Error("Exception during log download: " + ex); + return Array.Empty(); } } } diff --git a/Tests/FrameworkTests/OverwatchTranscript/TranscriptTests.cs b/Tests/FrameworkTests/OverwatchTranscript/TranscriptTests.cs index b88d3325..5e01752d 100644 --- a/Tests/FrameworkTests/OverwatchTranscript/TranscriptTests.cs +++ b/Tests/FrameworkTests/OverwatchTranscript/TranscriptTests.cs @@ -7,7 +7,7 @@ namespace FrameworkTests.OverwatchTranscript [TestFixture] public class TranscriptTests { - private const string TranscriptFilename = "testtranscript.json"; + private const string TranscriptFilename = "testtranscript.owts"; private const string HeaderKey = "testHeader"; private const string HeaderData = "abcdef"; private const string EventData0 = "12345"; diff --git a/Tools/OverwatchTranscript/Transcript.cs b/Tools/OverwatchTranscript/Transcript.cs new file mode 100644 index 00000000..f540872f --- /dev/null +++ b/Tools/OverwatchTranscript/Transcript.cs @@ -0,0 +1,20 @@ +namespace OverwatchTranscript +{ + public static class Transcript + { + public static ITranscriptWriter NewWriter() + { + return new TranscriptWriter(NewWorkDir()); + } + + public static ITranscriptReader NewReader(string transcriptFile) + { + return new TranscriptReader(NewWorkDir(), transcriptFile); + } + + private static string NewWorkDir() + { + return Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); + } + } +} diff --git a/Tools/OverwatchTranscript/TranscriptReader.cs b/Tools/OverwatchTranscript/TranscriptReader.cs index 2fbb1a78..fd0f8f2c 100644 --- a/Tools/OverwatchTranscript/TranscriptReader.cs +++ b/Tools/OverwatchTranscript/TranscriptReader.cs @@ -3,7 +3,15 @@ using System.IO.Compression; namespace OverwatchTranscript { - public class TranscriptReader + public interface ITranscriptReader + { + T GetHeader(string key); + void AddHandler(Action handler); + void Next(); + void Close(); + } + + public class TranscriptReader : ITranscriptReader { private readonly string transcriptFile; private readonly string artifactsFolder;