From f866e5f6484d59689cffe077be8c7d28a4f1289a Mon Sep 17 00:00:00 2001 From: benbierens Date: Wed, 22 Mar 2023 09:50:24 +0100 Subject: [PATCH] Better logging still --- CodexDistTestCore/FileManager.cs | 3 --- CodexDistTestCore/OnlineCodexNode.cs | 15 ++++++++++----- CodexDistTestCore/TestLog.cs | 8 ++++++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/CodexDistTestCore/FileManager.cs b/CodexDistTestCore/FileManager.cs index 94abe7a..f884b0a 100644 --- a/CodexDistTestCore/FileManager.cs +++ b/CodexDistTestCore/FileManager.cs @@ -28,7 +28,6 @@ namespace CodexDistTestCore var result = new TestFile(Path.Combine(Folder, Guid.NewGuid().ToString() + "_test.bin")); File.Create(result.Filename).Close(); activeFiles.Add(result); - log.Log($"Created test file '{result.Filename}'."); return result; } @@ -86,8 +85,6 @@ namespace CodexDistTestCore if (other == null) Assert.Fail("TestFile is null."); if (other == this || other!.Filename == Filename) Assert.Fail("TestFile is compared to itself."); - if (GetFileSize() != other.GetFileSize()) Assert.Fail("file sizes unequal?"); - using var stream1 = new FileStream(Filename, FileMode.Open, FileAccess.Read); using var stream2 = new FileStream(other.Filename, FileMode.Open, FileAccess.Read); diff --git a/CodexDistTestCore/OnlineCodexNode.cs b/CodexDistTestCore/OnlineCodexNode.cs index 1ce0c11..d8b1f6d 100644 --- a/CodexDistTestCore/OnlineCodexNode.cs +++ b/CodexDistTestCore/OnlineCodexNode.cs @@ -45,15 +45,20 @@ namespace CodexDistTestCore public TestFile? DownloadContent(ContentId contentId) { - Log($"Downloading for contentId: {contentId}"); + Log($"Downloading for contentId: {contentId.Id}"); var file = fileManager.CreateEmptyTestFile(); - using var fileStream = File.OpenWrite(file.Filename); - using var downloadStream = Http().HttpGetStream("download/" + contentId.Id); - downloadStream.CopyTo(fileStream); - Log($"Downloaded file of size {file.GetFileSize()}"); + DownloadToFile(contentId.Id, file); + Log($"Downloaded file of size {file.GetFileSize()} to {file.Filename}"); return file; } + private void DownloadToFile(string contentId, TestFile file) + { + using var fileStream = File.OpenWrite(file.Filename); + using var downloadStream = Http().HttpGetStream("download/" + contentId); + downloadStream.CopyTo(fileStream); + } + private Http Http() { return new Http(ip: "127.0.0.1", port: Container.ServicePort, baseUrl: "/api/codex/v1"); diff --git a/CodexDistTestCore/TestLog.cs b/CodexDistTestCore/TestLog.cs index 1ceb6b5..a2d33fd 100644 --- a/CodexDistTestCore/TestLog.cs +++ b/CodexDistTestCore/TestLog.cs @@ -30,8 +30,16 @@ namespace CodexDistTestCore var result = TestContext.CurrentContext.Result; Log($"Finished: {GetTestName()} = {result.Outcome.Status}"); + + if (!string.IsNullOrEmpty(result.Message)) + { + Log(result.Message); + } + if (result.Outcome.Status == NUnit.Framework.Interfaces.TestStatus.Failed) { + Log($"{result.StackTrace}"); + var logWriter = new PodLogWriter(file); logWriter.IncludeFullPodLogging(k8sManager); }