Skip to content

Commit

Permalink
wip: another stab at deflaking the CI
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind committed Mar 4, 2022
1 parent e2d8a23 commit 0568f13
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
27 changes: 13 additions & 14 deletions samples/unity-of-bugs/Assets/Scripts/SmokeTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void Start()
}
}

public static void InitSentry(SentryUnityOptions options, bool requireNative = true)
public static void InitSentry(SentryUnityOptions options, bool sentryDotNet)
{
options.Dsn = "http://publickey@localhost:8000/12345";
options.Debug = true;
Expand All @@ -111,19 +111,19 @@ public static void InitSentry(SentryUnityOptions options, bool requireNative = t
options.WindowsNativeSupportEnabled = true;
SentryNative.Configure(options);
#else
if (requireNative)
if (!sentryDotNet)
{
Debug.Log("SMOKE TEST: Given platform is not supported for native sentry configuration");
throw new Exception("Given platform is not supported");
}
#endif

Debug.Log("SMOKE TEST: SentryUnity Init.");
if (!requireNative)
{
SentryUnity.Init(options);
}
Debug.Log("SMOKE TEST: SentryUnity Init OK.");
// if (sentryDotNet)
// {
Debug.Log("SMOKE TEST: SentryUnity (.net) Init.");
SentryUnity.Init(options);
Debug.Log("SMOKE TEST: SentryUnity Init (.net) OK.");
// }
}

public static void SmokeTest()
Expand All @@ -133,7 +133,7 @@ public static void SmokeTest()
{
Debug.Log("SMOKE TEST: Start");

InitSentry(new SentryUnityOptions() { CreateHttpClientHandler = () => t }, false);
InitSentry(new SentryUnityOptions() { CreateHttpClientHandler = () => t }, true);

var currentMessage = 0;
t.ExpectMessage(currentMessage, "'type':'session'");
Expand Down Expand Up @@ -190,11 +190,10 @@ public static void SmokeTestCrash()
{
Debug.Log("SMOKE TEST: Start");

InitSentry(new SentryUnityOptions());

// const int sleepMs = 5000;
// Debug.Log($"SMOKE TEST: Sleep for {sleepMs} ms to avoid failure caused by the background data sync during sentry init.");
// Thread.Sleep(sleepMs);
// Note: we're disabling sentr-dotnet initialization in the crash test because the crash HTTP envelope
// isn't consistently received by our simple powershell HTTP server (crash-test-server.ps1). This is likely
// caused
InitSentry(new SentryUnityOptions(), sentryDotNet: false);

AddContext();

Expand Down
7 changes: 5 additions & 2 deletions src/Sentry.Unity.Native/SentryNativeBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ public static void Init(SentryUnityOptions options)
[DllImport("sentry")]
private static extern void sentry_options_set_logger(IntPtr options, sentry_logger_function_t logger, IntPtr userData);

// The logger we should forward native messages to.
// The logger we should forward native messages to. This is referenced by nativeLog() which in turn for.
private static IDiagnosticLogger? _logger;

// This method is called from the C library
// This method is called from the C library and forwards incoming messages to the currently set _logger.
[MonoPInvokeCallback(typeof(sentry_logger_function_t))]
private static void nativeLog(int cLevel, string message, IntPtr args, IntPtr userData)
{
Expand All @@ -145,6 +145,9 @@ private static void nativeLog(int cLevel, string message, IntPtr args, IntPtr us
return;
}

// If the message contains any "formatting" modifiers (that should be substituted by `args`), we need
// to apply the formatting. However, we cannot access C var-arg (va_list) in c# thus we pass it back to
// vsnprintf (to find out the length of the resulting buffer) & vsprintf (to actually format the message).
if (message.Contains("%"))
{
var formattedLength = vsnprintf(null, UIntPtr.Zero, message, args);
Expand Down
10 changes: 3 additions & 7 deletions test/Scripts.Integration.Test/crash-test-server.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ $httpServer = [System.Net.HttpListener]::new()
$httpServer.Prefixes.Add($uri)
$httpServer.Start()

write-Host "HTTP server listening on $uri"
Write-Host "HTTP server listening on $uri"
Write-Host "To stop the server, execute a GET request to ${uri}STOP"
Write-Host $separator

try {
while ($httpServer.IsListening) {
# allow ctrl+c interrupt using the AsyncWaitHandle
$contextAsync = $httpServer.GetContextAsync()
while (-not $contextAsync.AsyncWaitHandle.WaitOne(100)) { }

# current request info
$context = $contextAsync.GetAwaiter().GetResult()
$context = $httpServer.GetContext()

# print the request to stdout
write-Host "$($context.Request.HttpMethod) $($context.Request.Url)"
Expand Down

0 comments on commit 0568f13

Please sign in to comment.