wip connecting to codex plugin

This commit is contained in:
benbierens 2024-07-25 16:00:51 +02:00
parent 802b18e990
commit d58d65b751
No known key found for this signature in database
GPG Key ID: 877D2C2E09A22F3A
7 changed files with 97 additions and 16 deletions

View File

@ -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();
}
}
}

View File

@ -1,17 +1,5 @@
namespace OverwatchTranscript namespace OverwatchTranscript
{ {
[Serializable]
public partial class OverwatchHeader
{
public OverwatchCodexHeader? CodexHeader { get; set; }
}
[Serializable]
public partial class OverwatchEvent
{
public OverwatchCodexEvent? CodexEvent { get; set; }
}
[Serializable] [Serializable]
public class OverwatchCodexHeader public class OverwatchCodexHeader
{ {
@ -21,6 +9,7 @@
[Serializable] [Serializable]
public class OverwatchCodexEvent public class OverwatchCodexEvent
{ {
public ScenarioFinishedEvent? ScenarioFinished { get; set; }
public NodeStartedEvent? NodeStarted { get; set; } public NodeStartedEvent? NodeStarted { get; set; }
public NodeStoppedEvent? NodeStopped { get; set; } public NodeStoppedEvent? NodeStopped { get; set; }
public FileUploadedEvent? FileUploaded { get; set; } public FileUploadedEvent? FileUploaded { get; set; }
@ -30,6 +19,13 @@
#region Scenario Generated Events #region Scenario Generated Events
[Serializable]
public class ScenarioFinishedEvent
{
public bool Success { get; set; }
public string Result { get; set; } = string.Empty;
}
[Serializable] [Serializable]
public class NodeStartedEvent public class NodeStartedEvent
{ {

View File

@ -1,6 +1,7 @@
using CodexContractsPlugin; using CodexContractsPlugin;
using CodexNetDeployer; using CodexNetDeployer;
using CodexPlugin; using CodexPlugin;
using CodexPlugin.OverwatchSupport;
using CodexTests.Helpers; using CodexTests.Helpers;
using Core; using Core;
using DistTestCore; using DistTestCore;
@ -9,11 +10,15 @@ using DistTestCore.Logs;
using MetricsPlugin; using MetricsPlugin;
using Newtonsoft.Json; using Newtonsoft.Json;
using NUnit.Framework.Constraints; using NUnit.Framework.Constraints;
using OverwatchTranscript;
namespace CodexTests namespace CodexTests
{ {
public class CodexDistTest : DistTest public class CodexDistTest : DistTest
{ {
private const bool enableOverwatchTranscript = true;
private static readonly Dictionary<TestLifecycle, CodexTranscriptWriter> writers = new Dictionary<TestLifecycle, CodexTranscriptWriter>();
public CodexDistTest() public CodexDistTest()
{ {
ProjectPlugin.Load<CodexPlugin.CodexPlugin>(); ProjectPlugin.Load<CodexPlugin.CodexPlugin>();
@ -29,6 +34,25 @@ namespace CodexTests
localBuilder.Build(); 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() public ICodexNode StartCodex()
{ {
return StartCodex(s => { }); return StartCodex(s => { });
@ -50,6 +74,11 @@ namespace CodexTests
{ {
setup(s); setup(s);
OnCodexSetup(s); OnCodexSetup(s);
if (enableOverwatchTranscript)
{
s.WithTranscriptWriter(writers[Get()]);
}
}); });
return group; return group;

View File

@ -98,21 +98,29 @@ namespace DistTestCore
} }
} }
public void DownloadAllLogs() private IDownloadedLog[] allLogs = Array.Empty<IDownloadedLog>();
public IDownloadedLog[] DownloadAllLogs()
{ {
if (allLogs.Any()) return allLogs;
try try
{ {
var result = new List<IDownloadedLog>();
foreach (var rc in runningContainers) foreach (var rc in runningContainers)
{ {
foreach (var c in rc.Containers) foreach (var c in rc.Containers)
{ {
CoreInterface.DownloadLog(c); result.Add(CoreInterface.DownloadLog(c));
} }
} }
allLogs = result.ToArray();
return allLogs;
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.Error("Exception during log download: " + ex); Log.Error("Exception during log download: " + ex);
return Array.Empty<IDownloadedLog>();
} }
} }
} }

View File

@ -7,7 +7,7 @@ namespace FrameworkTests.OverwatchTranscript
[TestFixture] [TestFixture]
public class TranscriptTests public class TranscriptTests
{ {
private const string TranscriptFilename = "testtranscript.json"; private const string TranscriptFilename = "testtranscript.owts";
private const string HeaderKey = "testHeader"; private const string HeaderKey = "testHeader";
private const string HeaderData = "abcdef"; private const string HeaderData = "abcdef";
private const string EventData0 = "12345"; private const string EventData0 = "12345";

View File

@ -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());
}
}
}

View File

@ -3,7 +3,15 @@ using System.IO.Compression;
namespace OverwatchTranscript namespace OverwatchTranscript
{ {
public class TranscriptReader public interface ITranscriptReader
{
T GetHeader<T>(string key);
void AddHandler<T>(Action<DateTime, T> handler);
void Next();
void Close();
}
public class TranscriptReader : ITranscriptReader
{ {
private readonly string transcriptFile; private readonly string transcriptFile;
private readonly string artifactsFolder; private readonly string artifactsFolder;