[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:
Родитель
2cea3568b9
Коммит
b360408197
|
@ -77,13 +77,16 @@ namespace MonoTouchFixtures.CoreBluetooth {
|
|||
|
||||
CBCentralManager mgr;
|
||||
ManagerDelegate mgrDelegate;
|
||||
CBUUID heartRateMonitorUUID;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp ()
|
||||
{
|
||||
// iOS 13 and friends require bluetooth permission
|
||||
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.
|
||||
TestRuntime.AssertSystemVersion (PlatformName.MacOSX, 10, 11, throwIfOtherPlatform: false);
|
||||
var e = new AutoResetEvent (false);
|
||||
|
@ -94,7 +97,8 @@ namespace MonoTouchFixtures.CoreBluetooth {
|
|||
[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 ();
|
||||
}
|
||||
|
||||
|
@ -110,7 +114,6 @@ namespace MonoTouchFixtures.CoreBluetooth {
|
|||
Assert.NotNull (mgr.Delegate, "Delegate");
|
||||
}
|
||||
|
||||
[Ignore ("https://github.com/xamarin/xamarin-macios/issues/7108")]
|
||||
[Test, Timeout (5000)]
|
||||
public void ScanForPeripherals ()
|
||||
{
|
||||
|
@ -124,7 +127,6 @@ namespace MonoTouchFixtures.CoreBluetooth {
|
|||
}
|
||||
|
||||
#if !XAMCORE_3_0
|
||||
[Ignore ("https://github.com/xamarin/xamarin-macios/issues/7108")]
|
||||
[Test, Timeout (5000)]
|
||||
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);
|
||||
|
||||
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);
|
||||
} else {
|
||||
// that API was deprecated in 7.0 and removed from 9.0
|
||||
using (var uuid = CBUUID.FromString ("B9401000-F5F8-466E-AFF9-25556B57FE6D"))
|
||||
mgr.RetrievePeripherals (uuid);
|
||||
mgr.RetrievePeripherals (heartRateMonitorUUID);
|
||||
}
|
||||
}
|
||||
#endif // !XAMCORE_3_0
|
||||
|
|
Загрузка…
Ссылка в новой задаче