Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static async Task<int> Main()
});

var mode = SettingsHelper.GetSetting("mode") ?? string.Empty;
Console.WriteLine($"Mode is: {mode}");
NonBlockingConsole.WriteLine($"Mode is: {mode}");

if (mode.Equals("serviceonly"))
{
Expand All @@ -29,7 +29,8 @@ public static async Task<int> Main()
}
else
{
Console.WriteLine($"Unknown mode: {mode}");
NonBlockingConsole.WriteLine($"Unknown mode: {mode}");
NonBlockingConsole.FlushBeforeExit();
throw new Exception($"Unknown mode: {mode}");
}

Expand All @@ -47,7 +48,7 @@ static async Task RunExternalService(CancellationToken cancellationToken)
if (serviceConnectionType is ServiceConnectionType.Polling or ServiceConnectionType.PollingOverWebSocket)
{
addressToPoll = SettingsHelper.GetSetting("octopusservercommsport");
Console.WriteLine($"Will poll: {addressToPoll}");
NonBlockingConsole.WriteLine($"Will poll: {addressToPoll}");
}

var proxyDetails = SettingsHelper.GetProxyDetails();
Expand All @@ -67,22 +68,22 @@ static async Task RunExternalService(CancellationToken cancellationToken)
case ServiceConnectionType.PollingOverWebSocket:
FixHungWebSocketsHack.EnableHack();
var sslThubprint = SettingsHelper.GetSetting("sslthubprint");
Console.WriteLine($"Using SSL thumbprint: {sslThubprint}");
NonBlockingConsole.WriteLine($"Using SSL thumbprint: {sslThubprint}");

tentaclePolling.Poll(new Uri("poll://SQ-TENTAPOLL"), new ServiceEndPoint(new Uri(addressToPoll), sslThubprint, proxyDetails));
break;
case ServiceConnectionType.Listening:
var port = tentaclePolling.Listen();
Console.WriteLine($"Listening on port: {port}");
NonBlockingConsole.WriteLine($"Listening on port: {port}");
tentaclePolling.Trust(octopusThumbprint);
break;
default:
throw new ArgumentOutOfRangeException();
}

Console.WriteLine("RunningAndReady");
Console.WriteLine("Will Now sleep");
await Console.Out.FlushAsync();
NonBlockingConsole.WriteLine("RunningAndReady");
NonBlockingConsole.WriteLine("Will Now sleep");
await NonBlockingConsole.FlushAsync();

// Run until the Program is terminated
await StayAliveUntilHelper.WaitUntilSignaledToDie();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Halibut.TestUtils.Contracts;
using Halibut.TestUtils.SampleProgram.Base.LogUtils;

namespace Halibut.TestUtils.SampleProgram.Base
{
Expand All @@ -14,37 +15,37 @@ public DelegateCachingService(ICachingService cachingService)

public Guid NonCachableCall()
{
Console.WriteLine("Forwarding NonCachableCall() call to delegate");
NonBlockingConsole.WriteLine("Forwarding NonCachableCall() call to delegate");
return cachingService.NonCachableCall();
}

public Guid CachableCall()
{
Console.WriteLine("Forwarding CachableCall() call to delegate");
NonBlockingConsole.WriteLine("Forwarding CachableCall() call to delegate");
return cachingService.CachableCall();
}

public Guid CachableCall(Guid input)
{
Console.WriteLine("Forwarding CachableCall(Guid) call to delegate");
NonBlockingConsole.WriteLine("Forwarding CachableCall(Guid) call to delegate");
return cachingService.CachableCall(input);
}

public Guid AnotherCachableCall()
{
Console.WriteLine("Forwarding AnotherCachableCall() call to delegate");
NonBlockingConsole.WriteLine("Forwarding AnotherCachableCall() call to delegate");
return cachingService.AnotherCachableCall();
}

public Guid CachableCallThatThrowsAnExceptionWithARandomExceptionMessage(string exceptionMessagePrefix)
{
Console.WriteLine("Forwarding CachableCallThatThrowsAnExceptionWithARandomExceptionMessage() call to delegate");
NonBlockingConsole.WriteLine("Forwarding CachableCallThatThrowsAnExceptionWithARandomExceptionMessage() call to delegate");
return cachingService.CachableCallThatThrowsAnExceptionWithARandomExceptionMessage(exceptionMessagePrefix);
}

public Guid TwoSecondCachableCall()
{
Console.WriteLine("Forwarding TwoSecondCachableCall() call to delegate");
NonBlockingConsole.WriteLine("Forwarding TwoSecondCachableCall() call to delegate");
return cachingService.TwoSecondCachableCall();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using Halibut.TestUtils.Contracts;
using Halibut.TestUtils.SampleProgram.Base.LogUtils;
using Halibut.TestUtils.SampleProgram.Base.Utils;

namespace Halibut.TestUtils.SampleProgram.Base
Expand All @@ -16,19 +17,19 @@ public DelegateEchoService(IEchoService echoService)

public int LongRunningOperation()
{
Console.WriteLine("Forwarding LongRunningOperation() call to delegate");
NonBlockingConsole.WriteLine("Forwarding LongRunningOperation() call to delegate");
return echoService.LongRunningOperation();
}

public string SayHello(string name)
{
Console.WriteLine("Forwarding SayHello() call to delegate");
NonBlockingConsole.WriteLine("Forwarding SayHello() call to delegate");
return echoService.SayHello(name);
}

public bool Crash()
{
Console.WriteLine("Forwarding Crash() call to delegate");
NonBlockingConsole.WriteLine("Forwarding Crash() call to delegate");
try
{
return echoService.Crash();
Expand All @@ -44,7 +45,7 @@ public bool Crash()
public int CountBytes(DataStream dataStream)
{
dataStream = dataStream.ConfigureWriterOnReceivedDataStream();
Console.WriteLine("Forwarding CountBytes() call to delegate");
NonBlockingConsole.WriteLine("Forwarding CountBytes() call to delegate");
return echoService.CountBytes(dataStream);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Halibut.TestUtils.Contracts;
using Halibut.TestUtils.SampleProgram.Base.LogUtils;

namespace Halibut.TestUtils.SampleProgram.Base
{
Expand All @@ -14,115 +15,115 @@ public DelegateMultipleParametersTestService(IMultipleParametersTestService mult

public void MethodReturningVoid(long a, long b)
{
Console.WriteLine("Forwarding MethodReturningVoid() call to delegate");
NonBlockingConsole.WriteLine("Forwarding MethodReturningVoid() call to delegate");
multipleParametersTestService.MethodReturningVoid(a, b);
}

public long Add(long a, long b)
{
Console.WriteLine("Forwarding Add(long, long) call to delegate");
NonBlockingConsole.WriteLine("Forwarding Add(long, long) call to delegate");
return multipleParametersTestService.Add(a, b);
}

public double Add(double a, double b)
{
Console.WriteLine("Forwarding Add(double, double) call to delegate");
NonBlockingConsole.WriteLine("Forwarding Add(double, double) call to delegate");
return multipleParametersTestService.Add(a, b);
}

public decimal Add(decimal a, decimal b)
{
Console.WriteLine("Forwarding Add(decimal, decimal) call to delegate");
NonBlockingConsole.WriteLine("Forwarding Add(decimal, decimal) call to delegate");
return multipleParametersTestService.Add(a, b);
}

public string Hello()
{
Console.WriteLine("Forwarding Hello() call to delegate");
NonBlockingConsole.WriteLine("Forwarding Hello() call to delegate");
return multipleParametersTestService.Hello();
}

public string Hello(string a)
{
Console.WriteLine("Forwarding Hello(1 param) call to delegate");
NonBlockingConsole.WriteLine("Forwarding Hello(1 param) call to delegate");
return multipleParametersTestService.Hello(a);
}

public string Hello(string a, string b)
{
Console.WriteLine("Forwarding Hello(2 params) call to delegate");
NonBlockingConsole.WriteLine("Forwarding Hello(2 params) call to delegate");
return multipleParametersTestService.Hello(a, b);
}

public string Hello(string a, string b, string c)
{
Console.WriteLine("Forwarding Hello(3 params) call to delegate");
NonBlockingConsole.WriteLine("Forwarding Hello(3 params) call to delegate");
return multipleParametersTestService.Hello(a, b, c);
}

public string Hello(string a, string b, string c, string d)
{
Console.WriteLine("Forwarding Hello(4 params) call to delegate");
NonBlockingConsole.WriteLine("Forwarding Hello(4 params) call to delegate");
return multipleParametersTestService.Hello(a, b, c, d);
}

public string Hello(string a, string b, string c, string d, string e)
{
Console.WriteLine("Forwarding Hello(5 params) call to delegate");
NonBlockingConsole.WriteLine("Forwarding Hello(5 params) call to delegate");
return multipleParametersTestService.Hello(a, b, c, d, e);
}

public string Hello(string a, string b, string c, string d, string e, string f)
{
Console.WriteLine("Forwarding Hello(6 params) call to delegate");
NonBlockingConsole.WriteLine("Forwarding Hello(6 params) call to delegate");
return multipleParametersTestService.Hello(a, b, c, d, e, f);
}

public string Hello(string a, string b, string c, string d, string e, string f, string g)
{
Console.WriteLine("Forwarding Hello(7 params) call to delegate");
NonBlockingConsole.WriteLine("Forwarding Hello(7 params) call to delegate");
return multipleParametersTestService.Hello(a, b, c, d, e, f, g);
}

public string Hello(string a, string b, string c, string d, string e, string f, string g, string h)
{
Console.WriteLine("Forwarding Hello(8 params) call to delegate");
NonBlockingConsole.WriteLine("Forwarding Hello(8 params) call to delegate");
return multipleParametersTestService.Hello(a, b, c, d, e, f, g, h);
}

public string Hello(string a, string b, string c, string d, string e, string f, string g, string h, string i)
{
Console.WriteLine("Forwarding Hello(9 params) call to delegate");
NonBlockingConsole.WriteLine("Forwarding Hello(9 params) call to delegate");
return multipleParametersTestService.Hello(a, b, c, d, e, f, g, h, i);
}

public string Hello(string a, string b, string c, string d, string e, string f, string g, string h, string i, string j)
{
Console.WriteLine("Forwarding Hello(10 params) call to delegate");
NonBlockingConsole.WriteLine("Forwarding Hello(10 params) call to delegate");
return multipleParametersTestService.Hello(a, b, c, d, e, f, g, h, i, j);
}

public string Hello(string a, string b, string c, string d, string e, string f, string g, string h, string i, string j, string k)
{
Console.WriteLine("Forwarding Hello(11 params) call to delegate");
NonBlockingConsole.WriteLine("Forwarding Hello(11 params) call to delegate");
return multipleParametersTestService.Hello(a, b, c, d, e, f, g, h, i, j, k);
}

public string Ambiguous(string a, string b)
{
Console.WriteLine("Forwarding Ambiguous(string, string) call to delegate");
NonBlockingConsole.WriteLine("Forwarding Ambiguous(string, string) call to delegate");
return multipleParametersTestService.Ambiguous(a, b);
}

public string Ambiguous(string a, Tuple<string, string> b)
{
Console.WriteLine("Forwarding Ambiguous(string, Tuple) call to delegate");
NonBlockingConsole.WriteLine("Forwarding Ambiguous(string, Tuple) call to delegate");
return multipleParametersTestService.Ambiguous(a, b);
}

public MapLocation GetLocation(MapLocation loc)
{
Console.WriteLine("Forwarding GetLocation() call to delegate");
NonBlockingConsole.WriteLine("Forwarding GetLocation() call to delegate");
return multipleParametersTestService.GetLocation(loc);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Threading.Tasks;

namespace Halibut.TestUtils.SampleProgram.Base.LogUtils
{
/// <summary>
/// Use this instead of <see cref="Console.WriteLine(string)"/> everywhere in the compat binaries.
/// See <see cref="NonBlockingLineWriter"/> for why.
/// </summary>
public static class NonBlockingConsole
{
static readonly TimeSpan DefaultFlushTimeout = TimeSpan.FromSeconds(10);

static readonly NonBlockingLineWriter Writer = new(Console.Out, threadName: "CompatBinaryConsoleWriter");

public static void WriteLine(string line) => Writer.WriteLine(line);

/// <summary>
/// Waits for queued lines to reach stdout, e.g. so the test process sees "RunningAndReady".
/// </summary>
public static Task<bool> FlushAsync() => Writer.FlushAsync(DefaultFlushTimeout);

/// <summary>
/// Waits (briefly) for queued lines to reach stdout before the process exits.
/// </summary>
public static bool FlushBeforeExit() => Writer.Flush(TimeSpan.FromSeconds(2));
}
}
Loading