[Tests] Make the CoreBluetooth tests more reliable. (#7115)

Tests were failing because the manager was getting dispose and the
delegate was not. We ran into the failure because there was a device
close to the lab with the UUID that was being used.

The change uses a even more common UUID (heart monitor), which should
increase the chances to pick up a device and re-orgs the disposal of the
manager and the delegate.

This was confirmed with a BLE device, watchOS does not like us to try
and access it as a bluetooth device and is 'hacky'.

Fixes: https://github.com/xamarin/xamarin-macios/issues/7108
This commit is contained in:
Manuel de la Pena 2019-09-26 17:07:57 -04:00 коммит произвёл GitHub
Родитель 2cea3568b9
Коммит b360408197
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 9 добавлений и 7 удалений

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

@ -77,13 +77,16 @@ namespace MonoTouchFixtures.CoreBluetooth {
CBCentralManager mgr; CBCentralManager mgr;
ManagerDelegate mgrDelegate; ManagerDelegate mgrDelegate;
CBUUID heartRateMonitorUUID;
[SetUp] [SetUp]
public void SetUp () public void SetUp ()
{ {
// iOS 13 and friends require bluetooth permission // iOS 13 and friends require bluetooth permission
if (TestRuntime.CheckXcodeVersion (11, 0)) if (TestRuntime.CheckXcodeVersion (11, 0))
TestRuntime.CheckBluetoothPermission (); TestRuntime.CheckBluetoothPermission ();
//known UUID for a heart monitor, more common, we want to find something and make sure we do not crash
heartRateMonitorUUID = CBUUID.FromPartial (0x180D);
// Required API is available in macOS 10.8, but it doesn't work (hangs in 10.8-10.9, randomly crashes in 10.10) on the bots. // Required API is available in macOS 10.8, but it doesn't work (hangs in 10.8-10.9, randomly crashes in 10.10) on the bots.
TestRuntime.AssertSystemVersion (PlatformName.MacOSX, 10, 11, throwIfOtherPlatform: false); TestRuntime.AssertSystemVersion (PlatformName.MacOSX, 10, 11, throwIfOtherPlatform: false);
var e = new AutoResetEvent (false); var e = new AutoResetEvent (false);
@ -94,7 +97,8 @@ namespace MonoTouchFixtures.CoreBluetooth {
[TearDown] [TearDown]
public void TearDown () public void TearDown ()
{ {
// should dispose the delegate heartRateMonitorUUID?.Dispose ();
mgrDelegate?.Dispose (); // make sure that our delegate does not get messages after the mgr was disposed
mgr?.Dispose (); mgr?.Dispose ();
} }
@ -110,7 +114,6 @@ namespace MonoTouchFixtures.CoreBluetooth {
Assert.NotNull (mgr.Delegate, "Delegate"); Assert.NotNull (mgr.Delegate, "Delegate");
} }
[Ignore ("https://github.com/xamarin/xamarin-macios/issues/7108")]
[Test, Timeout (5000)] [Test, Timeout (5000)]
public void ScanForPeripherals () public void ScanForPeripherals ()
{ {
@ -124,7 +127,6 @@ namespace MonoTouchFixtures.CoreBluetooth {
} }
#if !XAMCORE_3_0 #if !XAMCORE_3_0
[Ignore ("https://github.com/xamarin/xamarin-macios/issues/7108")]
[Test, Timeout (5000)] [Test, Timeout (5000)]
public void RetrievePeripherals () public void RetrievePeripherals ()
{ {
@ -136,12 +138,12 @@ namespace MonoTouchFixtures.CoreBluetooth {
Assert.Inconclusive ("Bluetooth is off and therefore the test cannot be ran. State == {0}.", mgr.State); Assert.Inconclusive ("Bluetooth is off and therefore the test cannot be ran. State == {0}.", mgr.State);
if (TestRuntime.CheckXcodeVersion (7, 0)) { if (TestRuntime.CheckXcodeVersion (7, 0)) {
using (var uuid = new NSUuid ("B9401000-F5F8-466E-AFF9-25556B57FE6D")) // ToString in a CBUUID with true returns the full uuid which can be used to create a NSUuid
using (var uuid = new NSUuid (heartRateMonitorUUID.ToString (true)))
mgr.RetrievePeripheralsWithIdentifiers (uuid); mgr.RetrievePeripheralsWithIdentifiers (uuid);
} else { } else {
// that API was deprecated in 7.0 and removed from 9.0 // that API was deprecated in 7.0 and removed from 9.0
using (var uuid = CBUUID.FromString ("B9401000-F5F8-466E-AFF9-25556B57FE6D")) mgr.RetrievePeripherals (heartRateMonitorUUID);
mgr.RetrievePeripherals (uuid);
} }
} }
#endif // !XAMCORE_3_0 #endif // !XAMCORE_3_0