Skip to content

Commit

Permalink
Don't rely on default logging to get the port
Browse files Browse the repository at this point in the history
  • Loading branch information
adamreeve committed Oct 11, 2024
1 parent c765f1a commit f2e34a2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
using System.Threading.Tasks;
using Apache.Arrow.Flight.TestWeb;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace Apache.Arrow.Flight.IntegrationTest;
Expand All @@ -40,7 +43,7 @@ public async Task Execute()
throw new Exception($"Scenario '{_scenario}' is not supported.");
}

await Host.CreateDefaultBuilder()
var host = Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder
Expand All @@ -50,8 +53,16 @@ await Host.CreateDefaultBuilder()
})
.UseStartup<Startup>();
})
.Build()
.RunAsync()
.ConfigureAwait(false);
.Build();

await host.StartAsync().ConfigureAwait(false);

var addresses = host.Services.GetService<IServer>().Features.Get<IServerAddressesFeature>().Addresses;
foreach (var address in addresses)
{
Console.WriteLine($"Server listening on {address}");
}

await host.WaitForShutdownAsync().ConfigureAwait(false);
}
}
7 changes: 7 additions & 0 deletions csharp/test/Apache.Arrow.Flight.TestWeb/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;

namespace Apache.Arrow.Flight.TestWeb
{
Expand All @@ -31,6 +33,11 @@ public void ConfigureServices(IServiceCollection services)
.AddFlightServer<TestFlightServer>();

services.AddSingleton(new FlightStore());

// The integration tests rely on the port being written to the first line of stdout,
// so send all logging to stderr.
services.Configure<ConsoleLoggerOptions>(
o => o.LogToStandardErrorThreshold = LogLevel.Debug);
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand Down
3 changes: 1 addition & 2 deletions dev/archery/archery/integration/tester_csharp.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,8 @@ def flight_server(self, scenario_name=None):
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

try:
server.stdout.readline() # Skip first log line output
output = server.stdout.readline().decode()
if "Now listening on" not in output:
if not output.startswith("Server listening on "):
server.kill()
out, err = server.communicate()
raise RuntimeError(
Expand Down

0 comments on commit f2e34a2

Please sign in to comment.