From 9c8aa96221c4bc1b1e0a1f70559ccaa93c89b4d6 Mon Sep 17 00:00:00 2001 From: "E.Z. Hart" Date: Wed, 22 Jul 2020 01:51:44 -0600 Subject: [PATCH] Slow down simulated main thread queue for marshaling tests --- .../MarshalingObservableCollectionTests.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Xamarin.Forms.Core.UnitTests/MarshalingObservableCollectionTests.cs b/Xamarin.Forms.Core.UnitTests/MarshalingObservableCollectionTests.cs index 7654d3895fc..06c44152def 100644 --- a/Xamarin.Forms.Core.UnitTests/MarshalingObservableCollectionTests.cs +++ b/Xamarin.Forms.Core.UnitTests/MarshalingObservableCollectionTests.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Concurrent; +using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Reflection; @@ -50,7 +51,6 @@ public async Task AddOffUIThread() // Add an item from a threadpool thread await Task.Run(() => { - var x = Thread.CurrentThread.ManagedThreadId; source.Add(1); countFromThreadPool = moc.Count; }); @@ -232,12 +232,11 @@ class MarshalingTestPlatformServices : IPlatformServices { int _threadId; bool _running; - BlockingCollection _todo = new BlockingCollection(); + Queue _todo = new Queue(); public void Stop() { _running = false; - _todo.CompleteAdding(); } public void Start() @@ -254,7 +253,11 @@ public void Start() { try { - _todo.Take()?.Invoke(); + Thread.Sleep(100); + while (_todo.Count > 0) + { + _todo.Dequeue().Invoke(); + } } catch (Exception ex) { @@ -268,7 +271,7 @@ public void Start() public void BeginInvokeOnMainThread(Action action) { - _todo.Add(action); + _todo.Enqueue(action); } public OSAppTheme RequestedTheme { get; }