浏览代码

Fix and update Watson to latest (#10183)

Andreas Nägeli 4 天之前
父节点
当前提交
72cffb8bbb

+ 4 - 4
frameworks/CSharp/watson/Benchmarks/Benchmarks.csproj

@@ -2,8 +2,8 @@
   
   <PropertyGroup>
     
-    <TargetFramework>net5.0</TargetFramework>
-    <LangVersion>9.0</LangVersion>
+    <TargetFramework>net9.0</TargetFramework>
+    <LangVersion>13.0</LangVersion>
     
     <AssemblyTitle>EmbedIO Benchmarks</AssemblyTitle>
     <Description>Test suite to be executed with TechEmpower FrameworkBenchmarks.</Description>
@@ -17,8 +17,8 @@
   </PropertyGroup>
   
   <ItemGroup>
-    <PackageReference Include="System.Text.Json" Version="5.0.0" />
-    <PackageReference Include="Watson" Version="4.0.0.3" />
+    <PackageReference Include="System.Text.Json" Version="9.0.10" />
+    <PackageReference Include="Watson" Version="6.4.0" />
   </ItemGroup>
   
 </Project>

+ 12 - 12
frameworks/CSharp/watson/Benchmarks/Program.cs

@@ -1,11 +1,10 @@
 using System;
-using System.Linq;
-using System.Net;
 using System.Text.Json;
 using System.Threading;
 using System.Threading.Tasks;
 
 using WatsonWebserver;
+using WatsonWebserver.Core;
 
 namespace Benchmarks
 {
@@ -23,7 +22,7 @@ namespace Benchmarks
 
     public static class Program
     {
-        private static readonly ManualResetEvent _WaitEvent = new ManualResetEvent(false);
+        private static readonly ManualResetEvent WaitEvent = new(false);
 
         public static async Task<int> Main(string[] args)
         {
@@ -33,21 +32,23 @@ namespace Benchmarks
             var host = "tfb-server";
 #endif
 
-            using var server = new Server(host, 8080, false, DefaultRoute);
+            var settings = new WebserverSettings(host, 8080, false);
 
-            server.Routes.Static.Add(HttpMethod.GET, "/plaintext", PlaintextRoute);
-            server.Routes.Static.Add(HttpMethod.GET, "/json", JsonRoute);
+            using var server = new Webserver(settings, DefaultRoute);
+
+            server.Routes.PreAuthentication.Static.Add(HttpMethod.GET, "/plaintext", PlaintextRoute);
+            server.Routes.PreAuthentication.Static.Add(HttpMethod.GET, "/json", JsonRoute);
 
             try
             {
                 AppDomain.CurrentDomain.ProcessExit += (_, __) =>
                 {
-                    _WaitEvent.Set();
+                    WaitEvent.Set();
                 };
 
                 await server.StartAsync();
 
-                _WaitEvent.WaitOne();
+                WaitEvent.WaitOne();
 
                 return 0;
             }
@@ -59,22 +60,21 @@ namespace Benchmarks
             }
         }
 
-        static async Task DefaultRoute(HttpContext ctx)
+        static async Task DefaultRoute(HttpContextBase ctx)
         {
             ctx.Response.StatusCode = 404;
-            ctx.Response.StatusDescription = "Not Found";
 
             await ctx.Response.Send("Not found.");
         }
 
-        static async Task PlaintextRoute(HttpContext ctx)
+        static async Task PlaintextRoute(HttpContextBase ctx)
         {
             ctx.Response.Headers.Add("Content-Type", "text/plain; charset=UTF-8");
 
             await ctx.Response.Send("Hello, World!");
         }
 
-        static async Task JsonRoute(HttpContext ctx)
+        static async Task JsonRoute(HttpContextBase ctx)
         {
             var response = new JsonResult() { Message = "Hello, World!" };
             var serialized = JsonSerializer.Serialize(response);

+ 2 - 2
frameworks/CSharp/watson/README.md

@@ -6,11 +6,11 @@ See the [project website](https://github.com/jchristn/WatsonWebserver) for more
 
 **Language**
 
-* C# 9.0
+* C# 13.0
 
 **Platforms**
 
-* .NET 5
+* .NET 9
 
 **Web Servers**
 

+ 1 - 2
frameworks/CSharp/watson/benchmark_config.json

@@ -16,8 +16,7 @@
       "os": "Linux",
       "database_os": "Linux",
       "display_name": "Watson Webserver",
-      "notes": "",
-      "tags": ["broken"]
+      "notes": ""
     }
   }]
 }

+ 3 - 3
frameworks/CSharp/watson/watson.dockerfile

@@ -1,4 +1,4 @@
-FROM mcr.microsoft.com/dotnet/sdk:5.0-alpine AS build
+FROM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS build
 WORKDIR /source
 
 # copy csproj and restore as distinct layers
@@ -7,10 +7,10 @@ RUN dotnet restore -r linux-musl-x64
 
 # copy and publish app and libraries
 COPY Benchmarks/ .
-RUN dotnet publish -c release -o /app -r linux-musl-x64
+RUN dotnet publish -c release -o /app -r linux-musl-x64 --no-restore --self-contained
 
 # final stage/image
-FROM mcr.microsoft.com/dotnet/runtime-deps:5.0-alpine
+FROM mcr.microsoft.com/dotnet/runtime-deps:9.0-alpine
 WORKDIR /app
 COPY --from=build /app .