Project layout cleanup

This commit is contained in:
benbierens 2023-03-21 13:20:21 +01:00
parent 61166181fa
commit ca0bc9570b
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
22 changed files with 151 additions and 175 deletions

View File

@ -1,6 +1,6 @@
using k8s.Models;
namespace CodexDistTests.TestCore
namespace CodexDistTestCore
{
public class ActiveNode
{

View File

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

View File

@ -1,4 +1,4 @@
namespace CodexDistTests.TestCore
namespace CodexDistTestCore
{
public class CodexDebugResponse
{

View File

@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>CodexDistTests</RootNamespace>
<RootNamespace>CodexDistTestCore</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

View File

@ -1,6 +1,6 @@
using k8s.Models;
namespace CodexDistTests.TestCore
namespace CodexDistTestCore
{
public class CodexDockerImage
{

View File

@ -1,6 +1,6 @@
using NUnit.Framework;
namespace CodexDistTests.TestCore
namespace CodexDistTestCore
{
[SetUpFixture]
public abstract class DistTest

View File

@ -1,6 +1,6 @@
using NUnit.Framework;
namespace CodexDistTests.TestCore
namespace CodexDistTestCore
{
public interface IFileManager
{

View File

@ -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;

View File

@ -2,7 +2,7 @@
using k8s.Models;
using NUnit.Framework;
namespace CodexDistTests.TestCore
namespace CodexDistTestCore
{
public interface IK8sManager
{

View File

@ -1,4 +1,4 @@
namespace CodexDistTests.TestCore
namespace CodexDistTestCore
{
public class NumberSource
{

View File

@ -1,4 +1,4 @@
namespace CodexDistTests.TestCore
namespace CodexDistTestCore
{
public interface IOfflineCodexNode
{

View File

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

View File

@ -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)
{

View File

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

View File

@ -1,4 +1,4 @@
namespace CodexDistTests.TestCore
namespace CodexDistTestCore
{
public static class Utils
{

View File

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

View File

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="nunit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CodexDistTestCore\CodexDistTestCore.csproj" />
</ItemGroup>
</Project>

View File

@ -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<string,string> { { "codex-node", "dist-test" } }
},
Template = new V1PodTemplateSpec
{
Metadata = new V1ObjectMeta
{
Labels = new Dictionary<string,string> { { "codex-node", "dist-test" } }
},
Spec = new V1PodSpec
{
Containers = new List<V1Container>
{
new V1Container
{
Name = "codex-node",
Image = "thatbenbierens/nim-codex:sha-c9a62de",
Ports = new List<V1ContainerPort>
{
new V1ContainerPort
{
ContainerPort = 8080,
Name = "codex-api-port"
}
},
Env = new List<V1EnvVar>
{
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<string, string> { { "codex-node", "dist-test" } },
Ports = new List<V1ServicePort>
{
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<string, string> { { "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.");
}
}

18
README.md Normal file
View File

@ -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`

View File

@ -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()
//{

19
Tests/Tests.csproj Normal file
View File

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="nunit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CodexDistTestCore\CodexDistTestCore.csproj" />
</ItemGroup>
</Project>

37
cs-codex-dist-testing.sln Normal file
View File

@ -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