Browse Source

Add test suite for GenHTTP webserver (#5203)

Andreas Nägeli 5 years ago
parent
commit
27e5bce0ae

+ 38 - 0
frameworks/CSharp/genhttp/.gitignore

@@ -0,0 +1,38 @@
+[Oo]bj/
+[Bb]in/
+TestResults/
+.nuget/
+*.sln
+*.sln.ide/
+_ReSharper.*/
+.idea/
+packages/
+artifacts/
+PublishProfiles/
+.vs/
+*.user
+*.suo
+*.cache
+*.docstates
+_ReSharper.*
+nuget.exe
+*net45.csproj
+*net451.csproj
+*k10.csproj
+*.psess
+*.vsp
+*.pidb
+*.userprefs
+*DS_Store
+*.ncrunchsolution
+*.*sdf
+*.ipch
+*.swp
+*~
+.build/
+.testPublish/
+launchSettings.json
+BenchmarkDotNet.Artifacts/
+BDN.Generated/
+binaries/
+global.json

+ 23 - 0
frameworks/CSharp/genhttp/Benchmarks/Benchmarks.csproj

@@ -0,0 +1,23 @@
+<Project Sdk="Microsoft.NET.Sdk">
+  
+  <PropertyGroup>
+    
+    <TargetFramework>netcoreapp3.0</TargetFramework>
+
+    <LangVersion>8.0</LangVersion>
+    <Nullable>enable</Nullable>
+    
+    <AssemblyTitle>GenHTTP Benchmarks</AssemblyTitle>
+    <Description>Test suite to be executed with TechEmpower FrameworkBenchmarks.</Description>
+    
+    <StartupObject>Benchmarks.Program</StartupObject>    
+    <OutputType>Exe</OutputType>
+    
+  </PropertyGroup>
+    
+  <ItemGroup>
+    <PackageReference Include="GenHTTP.Core" Version="2.4.1" />
+    <PackageReference Include="GenHTTP.Modules.Webservices" Version="2.4.1" />
+  </ItemGroup>
+  
+</Project>

+ 52 - 0
frameworks/CSharp/genhttp/Benchmarks/Program.cs

@@ -0,0 +1,52 @@
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+
+using GenHTTP.Core;
+using GenHTTP.Modules.Core;
+using GenHTTP.Modules.Webservices;
+
+using Benchmarks.Tests;
+
+namespace Benchmarks
+{
+
+    public static class Program
+    {
+
+        public static int Main(string[] args)
+        {
+            try
+            {
+                var waitEvent = new AutoResetEvent(false);
+
+                AppDomain.CurrentDomain.ProcessExit += (s, e) =>
+                {
+                    waitEvent.Set();
+                };
+
+                var tests = Layout.Create()
+                                  .Add("plaintext", new PlaintextProvider())
+                                  .Add<JsonResource>("json");
+
+                var server = Server.Create()
+                                   .Router(tests)
+                                   .Compression(false);
+
+                using (var instance = server.Build())
+                {
+                    waitEvent.WaitOne();
+                }
+
+                return 0;
+            }
+            catch (Exception e)
+            {
+                Console.WriteLine(e);
+                return -1;
+            }
+        }
+
+    }
+
+}

+ 28 - 0
frameworks/CSharp/genhttp/Benchmarks/Tests/JsonResource.cs

@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using Newtonsoft.Json;
+
+using GenHTTP.Modules.Webservices;
+
+namespace Benchmarks.Tests
+{
+
+    public class JsonResult
+    {
+
+        [JsonProperty("message")]
+        public string? Message { get; set; }
+
+    }
+
+    public class JsonResource
+    {
+
+        [Method]
+        public JsonResult GetMessage() => new JsonResult() { Message = "Hello, World!" };
+
+    }
+
+}

+ 24 - 0
frameworks/CSharp/genhttp/Benchmarks/Tests/PlaintextProvider.cs

@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Text;
+
+using GenHTTP.Api.Modules;
+using GenHTTP.Api.Protocol;
+
+namespace Benchmarks.Tests
+{
+
+    public class PlaintextProvider : IContentProvider
+    {
+        private static readonly byte[] PAYLOAD = Encoding.ASCII.GetBytes("Hello, World!");
+
+        public IResponseBuilder Handle(IRequest request)
+        {
+            return request.Respond()
+                          .Content(new MemoryStream(PAYLOAD), ContentType.TextPlain);
+        }
+
+    }
+
+}

+ 22 - 0
frameworks/CSharp/genhttp/README.md

@@ -0,0 +1,22 @@
+# GenHTTP Tests on Linux
+
+See the [GenHTTP website](https://genhttp.org) for more information.
+
+## Infrastructure Software Versions
+
+**Language**
+
+* C# 8.0
+
+**Platforms**
+
+* .NET Core
+
+**Web Servers**
+
+* [GenHTTP](https://github.com/Kaliumhexacyanoferrat/GenHTTP)
+
+## Paths & Source for Tests
+
+* [Plaintext](Benchmarks/Tests/PlaintextProvider.cs): "/plaintext"
+* [JSON](Benchmarks/Tests/JsonResource.cs): "/json"

+ 22 - 0
frameworks/CSharp/genhttp/benchmark_config.json

@@ -0,0 +1,22 @@
+{
+  "framework": "genhttp",
+  "tests": [{
+    "default": {
+      "plaintext_url": "/plaintext",
+      "json_url": "/json",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Fullstack",
+      "database": "None",
+      "framework": "GenHTTP",
+      "language": "C#",
+      "orm": "Raw",
+      "platform": ".NET",
+      "webserver": "GenHTTP",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "GenHTTP",
+      "notes": ""
+    }
+  }]
+}

+ 21 - 0
frameworks/CSharp/genhttp/genhttp.dockerfile

@@ -0,0 +1,21 @@
+FROM mcr.microsoft.com/dotnet/core/sdk:3.0-alpine AS build
+WORKDIR /app
+
+# copy csproj and restore as distinct layers
+COPY Benchmarks/*.csproj ./Benchmarks/
+WORKDIR /app/Benchmarks
+RUN dotnet restore
+
+# copy and build app and libraries
+WORKDIR /app/
+COPY Benchmarks/. ./Benchmarks/
+WORKDIR /app/Benchmarks
+RUN dotnet publish -c Release -r linux-musl-x64 -o out --self-contained true /p:PublishTrimmed=true
+
+FROM mcr.microsoft.com/dotnet/core/runtime-deps:3.0-alpine AS runtime
+ENV DOCKER_FLAVOR=linux
+WORKDIR /app
+COPY --from=build /app/Benchmarks/out ./
+ENTRYPOINT ["./Benchmarks"]
+
+EXPOSE 8080