Skip to content

Commit

Permalink
Improve flaky test logs (#2246)
Browse files Browse the repository at this point in the history
* Improve flaky test logs

* Fix another flaky

* Docs changes

* Add missing value

---------

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
kblok and actions-user authored Jul 1, 2023
1 parent 082ac02 commit 8603d0e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ await page.GoToAsync("http://www.google.com"); // In case of fonts being loaded
await page.EvaluateExpressionHandleAsync("document.fonts.ready"); // Wait for fonts to be loaded. Omitting this might result in no text rendered in pdf.
await page.PdfAsync(outputFile);
```
<sup><a href='/lib/PuppeteerSharp.Tests/PageTests/PdfTests.cs#L29-L39' title='Snippet source file'>snippet source</a> | <a href='#snippet-pdfasync' title='Start of snippet'>anchor</a></sup>
<sup><a href='/lib/PuppeteerSharp.Tests/PageTests/PdfTests.cs#L30-L40' title='Snippet source file'>snippet source</a> | <a href='#snippet-pdfasync' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

### Inject HTML
Expand Down
6 changes: 4 additions & 2 deletions lib/PuppeteerSharp.Tests/PageTests/ExposeFunctionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,17 @@ public async Task ShouldKeepTheCallbackClean()

// For CI/CD debugging purposes
var session = (CDPSession)Page.Client;
var message = "Expected an empty callback list. Found: \n";

if (session.HasPendingCallbacks())
{
foreach(var pendingMessage in session.GetPendingMessages())
{
Console.WriteLine($"Pending message: {pendingMessage.Message}");
message += $" - {pendingMessage.Message}\n";
}
}

Assert.False(((CDPSession)Page.Client).HasPendingCallbacks());
Assert.False(((CDPSession)Page.Client).HasPendingCallbacks(), message);
}
}
}
8 changes: 6 additions & 2 deletions lib/PuppeteerSharp.Tests/PageTests/PdfTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using System.Threading.Tasks;
using Newtonsoft.Json;
using PuppeteerSharp.Media;
Expand Down Expand Up @@ -75,7 +76,10 @@ public async Task CanPrintToPDFAndStreamTheResult()
await Page.PdfAsync(outputFile);

var stream = await Page.PdfStreamAsync();
Assert.Equal(new FileInfo(outputFile).Length, stream.Length);

// Firefox in Linux might generate and of by one result here.
// If the difference is less than 2 bytes is good
Assert.True(Math.Abs(new FileInfo(outputFile).Length - stream.Length) < 2);
}

[PuppeteerFact]
Expand Down
1 change: 1 addition & 0 deletions lib/PuppeteerSharp/CDPSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public async Task<JObject> SendAsync(string method, object args = null, bool wai
{
TaskWrapper = new TaskCompletionSource<JObject>(TaskCreationOptions.RunContinuationsAsynchronously),
Method = method,
Message = message,
};
_callbacks[id] = callback;
}
Expand Down

0 comments on commit 8603d0e

Please sign in to comment.