Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feedback
  • Loading branch information
pavelsavara committed Aug 25, 2021
commit f6e28f261fea9b9e8e87aee000fda59416df370b
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31521.260
MinimumVisualStudioVersion = 10.0.40219.1
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUtilities", "..\Common\tests\TestUtilities\TestUtilities.csproj", "{B615DEB1-354C-4357-987A-BBA921E5A712}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Net.WebSockets.Client", "ref\System.Net.WebSockets.Client.csproj", "{BEA5BC2C-12D1-4D01-8D2C-5029578BD066}"
Expand Down Expand Up @@ -31,10 +27,10 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B615DEB1-354C-4357-987A-BBA921E5A712}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B615DEB1-354C-4357-987A-BBA921E5A712}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B615DEB1-354C-4357-987A-BBA921E5A712}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B615DEB1-354C-4357-987A-BBA921E5A712}.Release|Any CPU.Build.0 = Release|Any CPU
{90E8DA45-66F3-491E-B408-82AB85EEAB76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{90E8DA45-66F3-491E-B408-82AB85EEAB76}.Debug|Any CPU.Build.0 = Debug|Any CPU
{90E8DA45-66F3-491E-B408-82AB85EEAB76}.Release|Any CPU.ActiveCfg = Release|Any CPU
{90E8DA45-66F3-491E-B408-82AB85EEAB76}.Release|Any CPU.Build.0 = Release|Any CPU
{BEA5BC2C-12D1-4D01-8D2C-5029578BD066}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BEA5BC2C-12D1-4D01-8D2C-5029578BD066}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BEA5BC2C-12D1-4D01-8D2C-5029578BD066}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -43,22 +39,22 @@ Global
{0CD4C24D-7746-46F0-8D47-A396882B5468}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0CD4C24D-7746-46F0-8D47-A396882B5468}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0CD4C24D-7746-46F0-8D47-A396882B5468}.Release|Any CPU.Build.0 = Release|Any CPU
{90E8DA45-66F3-491E-B408-82AB85EEAB76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{90E8DA45-66F3-491E-B408-82AB85EEAB76}.Debug|Any CPU.Build.0 = Debug|Any CPU
{90E8DA45-66F3-491E-B408-82AB85EEAB76}.Release|Any CPU.ActiveCfg = Release|Any CPU
{90E8DA45-66F3-491E-B408-82AB85EEAB76}.Release|Any CPU.Build.0 = Release|Any CPU
{B615DEB1-354C-4357-987A-BBA921E5A712}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B615DEB1-354C-4357-987A-BBA921E5A712}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B615DEB1-354C-4357-987A-BBA921E5A712}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B615DEB1-354C-4357-987A-BBA921E5A712}.Release|Any CPU.Build.0 = Release|Any CPU
{8CD4D190-F656-4970-9AE9-4A9F8B30A2F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8CD4D190-F656-4970-9AE9-4A9F8B30A2F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8CD4D190-F656-4970-9AE9-4A9F8B30A2F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8CD4D190-F656-4970-9AE9-4A9F8B30A2F8}.Release|Any CPU.Build.0 = Release|Any CPU
{6B9721B2-00D0-41EC-96B9-6428CF1830CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6B9721B2-00D0-41EC-96B9-6428CF1830CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B9721B2-00D0-41EC-96B9-6428CF1830CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6B9721B2-00D0-41EC-96B9-6428CF1830CF}.Release|Any CPU.Build.0 = Release|Any CPU
{59A23CAB-D098-495F-A467-74C7553FF5BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{59A23CAB-D098-495F-A467-74C7553FF5BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{59A23CAB-D098-495F-A467-74C7553FF5BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{59A23CAB-D098-495F-A467-74C7553FF5BB}.Release|Any CPU.Build.0 = Release|Any CPU
{6B9721B2-00D0-41EC-96B9-6428CF1830CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6B9721B2-00D0-41EC-96B9-6428CF1830CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B9721B2-00D0-41EC-96B9-6428CF1830CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6B9721B2-00D0-41EC-96B9-6428CF1830CF}.Release|Any CPU.Build.0 = Release|Any CPU
{CA20532A-33B3-4DC0-92D2-EA6D7987D59F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CA20532A-33B3-4DC0-92D2-EA6D7987D59F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CA20532A-33B3-4DC0-92D2-EA6D7987D59F}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public class BrowserTimerThrottlingTest : ClientWebSocketTestBase
{
public static bool IsBrowser => RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER"));
const double moreThanLightThrottlingThreshold = 1900;
const double detectLightThrottlingThreshold = 950;
const double detectLightThrottlingThreshold = 900;
const double webSocketMessageFrequency = 45000;
const double fastTimeoutFrequency = 100;

public BrowserTimerThrottlingTest(ITestOutputHelper output) : base(output) { }

Expand All @@ -40,16 +42,14 @@ public async Task DotnetTimersAreHeavilyThrottledWithoutWebSocket()
DateTime start = DateTime.Now;
CancellationTokenSource cts = new CancellationTokenSource();

using (var timer = new Timers.Timer(100))
using (var timer = new Timers.Timer(fastTimeoutFrequency))
{
DateTime last = DateTime.Now;
DateTime lastSent = DateTime.MinValue;
timer.AutoReset = true;
timer.Enabled = true;
timer.Elapsed += (object? source, Timers.ElapsedEventArgs? e) =>
{
var ms = (e.SignalTime - last).TotalMilliseconds;
var msSent = (e.SignalTime - lastSent).TotalMilliseconds;
if (maxDelayMs < ms)
{
maxDelayMs = ms;
Expand All @@ -70,10 +70,6 @@ public async Task DotnetTimersAreHeavilyThrottledWithoutWebSocket()
Console.WriteLine("Slow tick NO-WS " + ms);
#endif
}
if (msSent > 45000)
{
lastSent = DateTime.Now;
}
last = e.SignalTime;
};

Expand All @@ -97,7 +93,7 @@ public async Task WebSocketKeepsDotnetTimersOnlyLightlyThrottled()
using (ClientWebSocket cws = await WebSocketHelper.GetConnectedWebSocket(Test.Common.Configuration.WebSockets.RemoteEchoServer, TimeOutMilliseconds, _output))
{
await SendAndReceive(cws, "test");
using (var timer = new Timers.Timer(100))
using (var timer = new Timers.Timer(fastTimeoutFrequency))
{
DateTime last = DateTime.Now;
DateTime lastSent = DateTime.MinValue;
Expand All @@ -114,7 +110,9 @@ public async Task WebSocketKeepsDotnetTimersOnlyLightlyThrottled()
if (ms > moreThanLightThrottlingThreshold)
{
// fail fast, we are throttled heavily
#if DEBUG
Console.WriteLine("Too slow tick " + ms);
#endif
cts.Cancel();
}
else if (ms > detectLightThrottlingThreshold)
Expand All @@ -125,7 +123,7 @@ public async Task WebSocketKeepsDotnetTimersOnlyLightlyThrottled()
Console.WriteLine("Slow tick WS " + ms);
#endif
}
if (msSent > 45000)
if (msSent > webSocketMessageFrequency)
{
await SendAndReceive(cws, "test");
lastSent = DateTime.Now;
Expand Down Expand Up @@ -162,11 +160,14 @@ private async static Task SendAndReceive(ClientWebSocket cws, string message)
}
catch (Exception ex)
{
#if DEBUG
Console.WriteLine("SendAndReceive fail:" + ex);
#endif
}
}
}

// this is just for convinience, as the second test has side-effect to running page, the first test would take longer if they are in another order
public class AlphabeticalOrderer : ITestCaseOrderer
{
public IEnumerable<TTestCase> OrderTestCases<TTestCase>(IEnumerable<TTestCase> testCases)
Expand Down
17 changes: 13 additions & 4 deletions src/mono/wasm/runtime/binding_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,16 @@ var BindingSupportLib = {
return Promise.resolve(js_obj) === js_obj ||
((typeof js_obj === "object" || typeof js_obj === "function") && typeof js_obj.then === "function")
};
this.isChromium = globalThis.navigator && globalThis.navigator.userAgent && globalThis.navigator.userAgent.includes("Chrome");
this.isChromium = false;
if (globalThis.navigator) {
var nav = globalThis.navigator;
if (nav.userAgentData && nav.userAgentData.brands) {
this.isChromium = nav.userAgentData.brands.some((i) => i.brand == 'Chromium');
}
else if (globalThis.navigator.userAgent) {
this.isChromium = nav.userAgent.includes("Chrome");
}
}

this._empty_string = "";
this._empty_string_ptr = 0;
Expand Down Expand Up @@ -373,7 +382,7 @@ var BindingSupportLib = {
return this._wrap_delegate_gc_handle_as_function(gc_handle);
},

_wrap_delegate_gc_handle_as_function: function (gc_handle, call_after_listener) {
_wrap_delegate_gc_handle_as_function: function (gc_handle, after_listener_callback) {
this.bindings_lazy_init ();

// see if we have js owned instance for this gc_handle already
Expand All @@ -386,8 +395,8 @@ var BindingSupportLib = {
const delegateRoot = MONO.mono_wasm_new_root (BINDING.get_js_owned_object_by_gc_handle(gc_handle));
try {
const res = BINDING.call_method(result[BINDING.delegate_invoke_symbol], delegateRoot.value, result[BINDING.delegate_invoke_signature_symbol], arguments);
if (call_after_listener) {
call_after_listener();
if (after_listener_callback) {
after_listener_callback();
}
return res;
} finally {
Expand Down
3 changes: 2 additions & 1 deletion src/mono/wasm/runtime/library_mono.js
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,8 @@ var MonoSupportLib = {
let now = new Date().valueOf();
const desired_reach_time = now + (1000 * 60 * 6);
const next_reach_time = Math.max(now + 1000, this.spread_timers_maximum);
for (var schedule = next_reach_time; schedule < desired_reach_time; schedule += 1000) {
const light_throttling_frequency = 1000;
for (var schedule = next_reach_time; schedule < desired_reach_time; schedule += light_throttling_frequency) {
const delay = schedule - now;
setTimeout(() => {
this.mono_wasm_set_timeout_exec(0);
Expand Down