From ca0bc9570b8a0353d3a96d619f7a5f54de651c13 Mon Sep 17 00:00:00 2001 From: benbierens Date: Tue, 21 Mar 2023 13:20:21 +0100 Subject: [PATCH] Project layout cleanup --- {TestCore => CodexDistTestCore}/ActiveNode.cs | 2 +- {TestCore => CodexDistTestCore}/ByteSize.cs | 16 +-- {TestCore => CodexDistTestCore}/CodexAPI.cs | 2 +- .../CodexDistTestCore.csproj | 4 +- .../CodexDockerImage.cs | 2 +- {TestCore => CodexDistTestCore}/DistTest.cs | 2 +- .../FileManager.cs | 2 +- {TestCore => CodexDistTestCore}/Http.cs | 4 +- {TestCore => CodexDistTestCore}/K8sManager.cs | 2 +- .../NumberSource.cs | 2 +- .../OfflineCodexNode.cs | 2 +- .../OnlineCodexNode.cs | 4 +- {TestCore => CodexDistTestCore}/TestLog.cs | 8 +- {TestCore => CodexDistTestCore}/Timing.cs | 4 +- {TestCore => CodexDistTestCore}/Utils.cs | 2 +- LongTests/BasicTests/SimpleTests.cs | 26 ++++ LongTests/LongTests.csproj | 19 +++ Program.cs | 125 ------------------ README.md | 18 +++ .../BasicTests/SimpleTests.cs | 24 +--- Tests/Tests.csproj | 19 +++ cs-codex-dist-testing.sln | 37 ++++++ 22 files changed, 151 insertions(+), 175 deletions(-) rename {TestCore => CodexDistTestCore}/ActiveNode.cs (98%) rename {TestCore => CodexDistTestCore}/ByteSize.cs (73%) rename {TestCore => CodexDistTestCore}/CodexAPI.cs (93%) rename cs-kubetry.csproj => CodexDistTestCore/CodexDistTestCore.csproj (84%) rename {TestCore => CodexDistTestCore}/CodexDockerImage.cs (97%) rename {TestCore => CodexDistTestCore}/DistTest.cs (98%) rename {TestCore => CodexDistTestCore}/FileManager.cs (98%) rename {TestCore => CodexDistTestCore}/Http.cs (97%) rename {TestCore => CodexDistTestCore}/K8sManager.cs (99%) rename {TestCore => CodexDistTestCore}/NumberSource.cs (93%) rename {TestCore => CodexDistTestCore}/OfflineCodexNode.cs (97%) rename {TestCore => CodexDistTestCore}/OnlineCodexNode.cs (97%) rename {TestCore => CodexDistTestCore}/TestLog.cs (96%) rename {TestCore => CodexDistTestCore}/Timing.cs (98%) rename {TestCore => CodexDistTestCore}/Utils.cs (87%) create mode 100644 LongTests/BasicTests/SimpleTests.cs create mode 100644 LongTests/LongTests.csproj delete mode 100644 Program.cs create mode 100644 README.md rename BasicTests/DebugEndpointTests.cs => Tests/BasicTests/SimpleTests.cs (72%) create mode 100644 Tests/Tests.csproj create mode 100644 cs-codex-dist-testing.sln diff --git a/TestCore/ActiveNode.cs b/CodexDistTestCore/ActiveNode.cs similarity index 98% rename from TestCore/ActiveNode.cs rename to CodexDistTestCore/ActiveNode.cs index a9892ff..a5df3b7 100644 --- a/TestCore/ActiveNode.cs +++ b/CodexDistTestCore/ActiveNode.cs @@ -1,6 +1,6 @@ using k8s.Models; -namespace CodexDistTests.TestCore +namespace CodexDistTestCore { public class ActiveNode { diff --git a/TestCore/ByteSize.cs b/CodexDistTestCore/ByteSize.cs similarity index 73% rename from TestCore/ByteSize.cs rename to CodexDistTestCore/ByteSize.cs index f7edfc5..e8f5c92 100644 --- a/TestCore/ByteSize.cs +++ b/CodexDistTestCore/ByteSize.cs @@ -1,4 +1,4 @@ -namespace CodexDistTests.TestCore +namespace CodexDistTestCore { public class ByteSize { @@ -21,37 +21,37 @@ public static ByteSize MB(this long i) { - return KB(i * Kilo); + return (i * Kilo).KB(); } public static ByteSize GB(this long i) { - return MB(i * Kilo); + return (i * Kilo).MB(); } public static ByteSize TB(this long i) { - return GB(i * Kilo); + return (i * Kilo).GB(); } public static ByteSize KB(this int i) { - return KB(Convert.ToInt64(i)); + return Convert.ToInt64(i).KB(); } public static ByteSize MB(this int i) { - return MB(Convert.ToInt64(i)); + return Convert.ToInt64(i).MB(); } public static ByteSize GB(this int i) { - return GB(Convert.ToInt64(i)); + return Convert.ToInt64(i).GB(); } public static ByteSize TB(this int i) { - return TB(Convert.ToInt64(i)); + return Convert.ToInt64(i).TB(); } } } diff --git a/TestCore/CodexAPI.cs b/CodexDistTestCore/CodexAPI.cs similarity index 93% rename from TestCore/CodexAPI.cs rename to CodexDistTestCore/CodexAPI.cs index bc7351d..997cd3c 100644 --- a/TestCore/CodexAPI.cs +++ b/CodexDistTestCore/CodexAPI.cs @@ -1,4 +1,4 @@ -namespace CodexDistTests.TestCore +namespace CodexDistTestCore { public class CodexDebugResponse { diff --git a/cs-kubetry.csproj b/CodexDistTestCore/CodexDistTestCore.csproj similarity index 84% rename from cs-kubetry.csproj rename to CodexDistTestCore/CodexDistTestCore.csproj index ee4e349..a42e9be 100644 --- a/cs-kubetry.csproj +++ b/CodexDistTestCore/CodexDistTestCore.csproj @@ -1,8 +1,8 @@ - + net6.0 - CodexDistTests + CodexDistTestCore enable enable diff --git a/TestCore/CodexDockerImage.cs b/CodexDistTestCore/CodexDockerImage.cs similarity index 97% rename from TestCore/CodexDockerImage.cs rename to CodexDistTestCore/CodexDockerImage.cs index 6a85dac..42b4137 100644 --- a/TestCore/CodexDockerImage.cs +++ b/CodexDistTestCore/CodexDockerImage.cs @@ -1,6 +1,6 @@ using k8s.Models; -namespace CodexDistTests.TestCore +namespace CodexDistTestCore { public class CodexDockerImage { diff --git a/TestCore/DistTest.cs b/CodexDistTestCore/DistTest.cs similarity index 98% rename from TestCore/DistTest.cs rename to CodexDistTestCore/DistTest.cs index 9150ccf..ff51d62 100644 --- a/TestCore/DistTest.cs +++ b/CodexDistTestCore/DistTest.cs @@ -1,6 +1,6 @@ using NUnit.Framework; -namespace CodexDistTests.TestCore +namespace CodexDistTestCore { [SetUpFixture] public abstract class DistTest diff --git a/TestCore/FileManager.cs b/CodexDistTestCore/FileManager.cs similarity index 98% rename from TestCore/FileManager.cs rename to CodexDistTestCore/FileManager.cs index b77d227..a040e09 100644 --- a/TestCore/FileManager.cs +++ b/CodexDistTestCore/FileManager.cs @@ -1,6 +1,6 @@ using NUnit.Framework; -namespace CodexDistTests.TestCore +namespace CodexDistTestCore { public interface IFileManager { diff --git a/TestCore/Http.cs b/CodexDistTestCore/Http.cs similarity index 97% rename from TestCore/Http.cs rename to CodexDistTestCore/Http.cs index 5be0e1d..1cff3c8 100644 --- a/TestCore/Http.cs +++ b/CodexDistTestCore/Http.cs @@ -2,7 +2,7 @@ using NUnit.Framework; using System.Net.Http.Headers; -namespace CodexDistTests.TestCore +namespace CodexDistTestCore { public class Http { @@ -34,7 +34,7 @@ namespace CodexDistTests.TestCore public string HttpPostStream(string route, Stream stream) { - return Retry(() => + return Retry(() => { using var client = GetClient(); var url = GetUrl() + route; diff --git a/TestCore/K8sManager.cs b/CodexDistTestCore/K8sManager.cs similarity index 99% rename from TestCore/K8sManager.cs rename to CodexDistTestCore/K8sManager.cs index 971992e..5a61217 100644 --- a/TestCore/K8sManager.cs +++ b/CodexDistTestCore/K8sManager.cs @@ -2,7 +2,7 @@ using k8s.Models; using NUnit.Framework; -namespace CodexDistTests.TestCore +namespace CodexDistTestCore { public interface IK8sManager { diff --git a/TestCore/NumberSource.cs b/CodexDistTestCore/NumberSource.cs similarity index 93% rename from TestCore/NumberSource.cs rename to CodexDistTestCore/NumberSource.cs index 0ef5177..3dfa07b 100644 --- a/TestCore/NumberSource.cs +++ b/CodexDistTestCore/NumberSource.cs @@ -1,4 +1,4 @@ -namespace CodexDistTests.TestCore +namespace CodexDistTestCore { public class NumberSource { diff --git a/TestCore/OfflineCodexNode.cs b/CodexDistTestCore/OfflineCodexNode.cs similarity index 97% rename from TestCore/OfflineCodexNode.cs rename to CodexDistTestCore/OfflineCodexNode.cs index 7f3511c..6eb018f 100644 --- a/TestCore/OfflineCodexNode.cs +++ b/CodexDistTestCore/OfflineCodexNode.cs @@ -1,4 +1,4 @@ -namespace CodexDistTests.TestCore +namespace CodexDistTestCore { public interface IOfflineCodexNode { diff --git a/TestCore/OnlineCodexNode.cs b/CodexDistTestCore/OnlineCodexNode.cs similarity index 97% rename from TestCore/OnlineCodexNode.cs rename to CodexDistTestCore/OnlineCodexNode.cs index a33150c..d6db1af 100644 --- a/TestCore/OnlineCodexNode.cs +++ b/CodexDistTestCore/OnlineCodexNode.cs @@ -1,6 +1,6 @@ using NUnit.Framework; -namespace CodexDistTests.TestCore +namespace CodexDistTestCore { public interface IOnlineCodexNode { @@ -65,7 +65,7 @@ namespace CodexDistTests.TestCore { Id = id; } - + public string Id { get; } } } diff --git a/TestCore/TestLog.cs b/CodexDistTestCore/TestLog.cs similarity index 96% rename from TestCore/TestLog.cs rename to CodexDistTestCore/TestLog.cs index 9dea292..3854cd1 100644 --- a/TestCore/TestLog.cs +++ b/CodexDistTestCore/TestLog.cs @@ -1,6 +1,6 @@ using NUnit.Framework; -namespace CodexDistTests.TestCore +namespace CodexDistTestCore { public class TestLog { @@ -13,7 +13,7 @@ namespace CodexDistTests.TestCore file!.Write(message); } - public static void Error(string message) + public static void Error(string message) { Log($"[ERROR] {message}"); } @@ -32,7 +32,7 @@ namespace CodexDistTests.TestCore { if (file == null) throw new InvalidOperationException("No test is started!"); - + var result = TestContext.CurrentContext.Result; Log($"Finished: {GetTestName()} = {result.Outcome.Status}"); @@ -104,7 +104,7 @@ namespace CodexDistTests.TestCore { try { - File.AppendAllLines(filename + subfile + ".log", new[] { message }); + File.AppendAllLines(filename + subfile + ".log", new[] { message }); } catch (Exception ex) { diff --git a/TestCore/Timing.cs b/CodexDistTestCore/Timing.cs similarity index 98% rename from TestCore/Timing.cs rename to CodexDistTestCore/Timing.cs index f41b5fd..26c49b2 100644 --- a/TestCore/Timing.cs +++ b/CodexDistTestCore/Timing.cs @@ -1,6 +1,6 @@ using NUnit.Framework; -namespace CodexDistTests.TestCore +namespace CodexDistTestCore { [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] public class UseLongTimeoutsAttribute : PropertyAttribute @@ -78,7 +78,7 @@ namespace CodexDistTests.TestCore { return TimeSpan.FromSeconds(1); } - + public TimeSpan K8sOperationTimeout() { return TimeSpan.FromMinutes(5); diff --git a/TestCore/Utils.cs b/CodexDistTestCore/Utils.cs similarity index 87% rename from TestCore/Utils.cs rename to CodexDistTestCore/Utils.cs index d36072e..e0149a1 100644 --- a/TestCore/Utils.cs +++ b/CodexDistTestCore/Utils.cs @@ -1,4 +1,4 @@ -namespace CodexDistTests.TestCore +namespace CodexDistTestCore { public static class Utils { diff --git a/LongTests/BasicTests/SimpleTests.cs b/LongTests/BasicTests/SimpleTests.cs new file mode 100644 index 0000000..8c71653 --- /dev/null +++ b/LongTests/BasicTests/SimpleTests.cs @@ -0,0 +1,26 @@ +using CodexDistTestCore; +using NUnit.Framework; + +namespace LongTests.BasicTests +{ + [TestFixture] + public class SimpleTests : DistTest + { + [Test, UseLongTimeouts] + public void OneClientLargeFileTest() + { + var primary = SetupCodexNode() + .WithLogLevel(CodexLogLevel.Warn) + .WithStorageQuota(10.GB()) + .BringOnline(); + + var testFile = GenerateTestFile(1.GB()); + + var contentId = primary.UploadFile(testFile); + + var downloadedFile = primary.DownloadContent(contentId); + + testFile.AssertIsEqual(downloadedFile); + } + } +} diff --git a/LongTests/LongTests.csproj b/LongTests/LongTests.csproj new file mode 100644 index 0000000..fc5152f --- /dev/null +++ b/LongTests/LongTests.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/Program.cs b/Program.cs deleted file mode 100644 index cc7390d..0000000 --- a/Program.cs +++ /dev/null @@ -1,125 +0,0 @@ -using k8s; -using k8s.Models; - -public static class NotProgram -{ - private const string ns = "codex-test-namespace"; - - public static void NotMain(string[] args) - { - Console.WriteLine("Hello, World!"); - - var config = KubernetesClientConfiguration.BuildConfigFromConfigFile(); - var client = new Kubernetes(config); - - var deploymentSpec = new V1Deployment - { - ApiVersion= "apps/v1", - Metadata = new V1ObjectMeta - { - Name = "codex-demo", - NamespaceProperty = ns - }, - Spec = new V1DeploymentSpec - { - Replicas = 1, - Selector = new V1LabelSelector - { - MatchLabels = new Dictionary { { "codex-node", "dist-test" } } - }, - Template = new V1PodTemplateSpec - { - Metadata = new V1ObjectMeta - { - Labels = new Dictionary { { "codex-node", "dist-test" } } - }, - Spec = new V1PodSpec - { - Containers = new List - { - new V1Container - { - Name = "codex-node", - Image = "thatbenbierens/nim-codex:sha-c9a62de", - Ports = new List - { - new V1ContainerPort - { - ContainerPort = 8080, - Name = "codex-api-port" - } - }, - Env = new List - { - new V1EnvVar - { - Name = "LOG_LEVEL", - Value = "WARN" - } - } - } - } - } - } - } - }; - - var serviceSpec = new V1Service - { - ApiVersion = "v1", - Metadata = new V1ObjectMeta - { - Name = "codex-entrypoint", - NamespaceProperty = ns - }, - Spec = new V1ServiceSpec - { - Type = "NodePort", - Selector = new Dictionary { { "codex-node", "dist-test" } }, - Ports = new List - { - new V1ServicePort - { - Protocol = "TCP", - Port = 8080, - TargetPort = "codex-api-port", - NodePort = 30001 - } - } - } - }; - - Console.WriteLine("specs made"); - - var ans = client.CreateNamespace(new V1Namespace - { - ApiVersion = "v1", - Metadata = new V1ObjectMeta - { - Name = ns, - Labels = new Dictionary { { "name", ns } } - } - }); - - Console.WriteLine("created namespace"); - - var deployment = client.CreateNamespacedDeployment(deploymentSpec, ns); - - Console.WriteLine("deploy made"); - - var service = client.CreateNamespacedService(serviceSpec, ns); - - Console.WriteLine("Service up. Press Q to close..."); - var s = ""; - while (!s.StartsWith("q")) - { - s = Console.ReadLine(); - } - - client.DeleteNamespacedService(service.Name(), ns); - client.DeleteNamespacedDeployment(deployment.Name(), ns); - client.DeleteNamespace(ans.Name()); - - Console.WriteLine("Done."); - } -} diff --git a/README.md b/README.md new file mode 100644 index 0000000..1c0fb45 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# Distributed System Tests for Nim-Codex + +Nim-Codex: https://github.com/status-im/nim-codex + +Tests are built on dotnet v6.0 and Kubernetes v1.25.4, using dotnet-kubernetes SDK: https://github.com/kubernetes-client/csharp + +## Requirement + +At this moment, the tests require a local kubernetes cluster to be installed. + +## Run + +Short tests: These tests may take minutes to an hour. +`dotnet test Tests` + +Long tests: These may takes hours to days. +`dotnet test LongTests` + diff --git a/BasicTests/DebugEndpointTests.cs b/Tests/BasicTests/SimpleTests.cs similarity index 72% rename from BasicTests/DebugEndpointTests.cs rename to Tests/BasicTests/SimpleTests.cs index fef0cec..2b7b729 100644 --- a/BasicTests/DebugEndpointTests.cs +++ b/Tests/BasicTests/SimpleTests.cs @@ -1,11 +1,10 @@ -using CodexDistTests.TestCore; +using CodexDistTestCore; using NUnit.Framework; -using System; -namespace CodexDistTests.BasicTests +namespace Tests.BasicTests { [TestFixture] - public class DebugEndpointTests : DistTest + public class SimpleTests : DistTest { [Test] public void GetDebugInfo() @@ -37,23 +36,6 @@ namespace CodexDistTests.BasicTests testFile.AssertIsEqual(downloadedFile); } - [Test, UseLongTimeouts] - public void OneClientLargeFileTest() - { - var primary = SetupCodexNode() - .WithLogLevel(CodexLogLevel.Warn) - .WithStorageQuota(10.GB()) - .BringOnline(); - - var testFile = GenerateTestFile(1.GB()); - - var contentId = primary.UploadFile(testFile); - - var downloadedFile = primary.DownloadContent(contentId); - - testFile.AssertIsEqual(downloadedFile); - } - //[Test] //public void TwoClientTest() //{ diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj new file mode 100644 index 0000000..fc5152f --- /dev/null +++ b/Tests/Tests.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/cs-codex-dist-testing.sln b/cs-codex-dist-testing.sln new file mode 100644 index 0000000..9a7a7ad --- /dev/null +++ b/cs-codex-dist-testing.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33213.308 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{57F57B85-A537-4D3A-B7AE-B72C66B74AAB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LongTests", "LongTests\LongTests.csproj", "{AFCE270E-F844-4A7C-9006-69AE622BB1F4}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodexDistTestCore", "CodexDistTestCore\CodexDistTestCore.csproj", "{19306DE1-CEE5-4F7B-AA5D-FD91926D853D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {57F57B85-A537-4D3A-B7AE-B72C66B74AAB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {57F57B85-A537-4D3A-B7AE-B72C66B74AAB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {57F57B85-A537-4D3A-B7AE-B72C66B74AAB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {57F57B85-A537-4D3A-B7AE-B72C66B74AAB}.Release|Any CPU.Build.0 = Release|Any CPU + {AFCE270E-F844-4A7C-9006-69AE622BB1F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AFCE270E-F844-4A7C-9006-69AE622BB1F4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AFCE270E-F844-4A7C-9006-69AE622BB1F4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AFCE270E-F844-4A7C-9006-69AE622BB1F4}.Release|Any CPU.Build.0 = Release|Any CPU + {19306DE1-CEE5-4F7B-AA5D-FD91926D853D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {19306DE1-CEE5-4F7B-AA5D-FD91926D853D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {19306DE1-CEE5-4F7B-AA5D-FD91926D853D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {19306DE1-CEE5-4F7B-AA5D-FD91926D853D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {237BF0AA-9EC4-4659-AD9A-65DEB974250C} + EndGlobalSection +EndGlobal