[tests] Make CFNotificationCenterTest.TestNullNameAndObserver wait for notifications. Hopefully fixes #xamarin/maccore@1440. (#16699)

Hopefully fixes https://github.com/xamarin/maccore/issues/1440.
This commit is contained in:
Rolf Bjarne Kvinge 2022-11-11 13:42:49 +01:00 коммит произвёл GitHub
Родитель 9fb6a4b309
Коммит 380cb06077
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 7 добавлений и 3 удалений

Просмотреть файл

@ -8,6 +8,7 @@
//
using System;
using System.Threading;
using Foundation;
using CoreFoundation;
@ -77,16 +78,19 @@ namespace MonoTouchFixtures.CoreFoundation {
public void TestNullNameAndObserver ()
{
var d = CFNotificationCenter.Local;
bool mornNotification = false;
var mornNotification = new ManualResetEvent (false);
var token = d.AddObserver (null, null, (n, i) => mornNotification = n == "MornNotification");
var token = d.AddObserver (null, null, (n, i) => {
if (n == "MornNotification")
mornNotification.Set ();
});
// When not listening for a specific name nor observing an specific object
// we will get all notifications posted to NSNotificationCenter/Local CFNotificationCenter
NSNotificationCenter.DefaultCenter.PostNotificationName ("MornNotification", null);
d.RemoveObserver (token);
Assert.IsTrue (mornNotification);
Assert.IsTrue (mornNotification.WaitOne (TimeSpan.FromSeconds (10)), "Didn't get a notification after waiting 10 seconds.");
}
[Test]