Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
astroman133 committed Jun 1, 2020
2 parents d2dbec0 + ae2a4e7 commit 16b6d33
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 10 deletions.
13 changes: 10 additions & 3 deletions DeviceHub/DeviceManagers/DomeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,25 @@ public bool Connect( string domeID )
Task task = Task.Run( () =>
{
ReadInitialDomeDataTask();
StartDevicePolling();
} );

task.Wait();
task.Wait(); // This will propagate any unhandled exception
}
catch ( Exception )
catch ( AggregateException xcp )
{
LogActivityLine( ActivityMessageTypes.Other, "Attempting to initialize dome operation caught an unhandled exception. Details follow:" );
LogActivityLine( ActivityMessageTypes.Other, xcp.InnerException.ToString() );

Connected = false;
IsConnected = false;
ReleaseDomeService();
}

if ( Connected )
{
StartDevicePolling();
}

retval = Connected;
}

Expand Down
13 changes: 10 additions & 3 deletions DeviceHub/DeviceManagers/FocuserManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,25 @@ public bool Connect( string focuserID )
Task task = Task.Run( () =>
{
ReadInitialFocuserDataTask();
StartDevicePolling();
} );

task.Wait();
task.Wait(); // This will propagate any unhandled exception
}
catch ( Exception )
catch ( AggregateException xcp )
{
LogActivityLine( ActivityMessageTypes.Other, "Attempting to initialize focuser operation caught an unhandled exception. Details follow:" );
LogActivityLine( ActivityMessageTypes.Other, xcp.InnerException.ToString() );

Connected = false;
IsConnected = false;
ReleaseFocuserService();
}

if ( Connected )
{
StartDevicePolling();
}

retval = Connected;
}

Expand Down
14 changes: 11 additions & 3 deletions DeviceHub/DeviceManagers/TelescopeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,26 @@ public bool Connect( string scopeID )
Task task = Task.Run( () =>
{
ReadInitialTelescopeDataTask();
StartDevicePolling();
} );

task.Wait();
task.Wait(); // This will propagate any unhandled exception

}
catch ( Exception )
catch ( AggregateException xcp )
{
LogActivityLine( ActivityMessageTypes.Other, "Attempting to initialize telescope operation caught an unhandled exception. Details follow:" );
LogActivityLine( ActivityMessageTypes.Other, xcp.InnerException.ToString() );

Connected = false;
IsConnected = false;
ReleaseTelescopeService();
}

if (Connected )
{
StartDevicePolling();
}

retval = Connected;
}

Expand Down
8 changes: 8 additions & 0 deletions Unit Tests/Mock Services/MockTelescopeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public class MockTelescopeService : ITelescopeService
public IAxisRates MockSecondaryAxisRates { get; set; }
public IAxisRates MockTertiaryAxisRates { get; set; }
public bool MockIsWeakDriver { get; set; }
public bool MockNullPrimaryAxisRates { get; set; }

private Vector _targetAxes;
private Vector _mountAxes;
Expand Down Expand Up @@ -126,6 +127,8 @@ public MockTelescopeService()
MockPrimaryAxisRates = new AxisRates( TelescopeAxes.axisPrimary );
MockSecondaryAxisRates = new AxisRates( TelescopeAxes.axisSecondary );
MockTertiaryAxisRates = new AxisRates( TelescopeAxes.axisTertiary );

MockNullPrimaryAxisRates = false;
}

public bool Initialized { get; private set; }
Expand Down Expand Up @@ -465,6 +468,11 @@ public IAxisRates AxisRates( TelescopeAxes axis )
{
if ( axis == TelescopeAxes.axisPrimary )
{
if ( MockNullPrimaryAxisRates )
{
return null;
}

return MockPrimaryAxisRates;
}
else if ( axis == TelescopeAxes.axisSecondary )
Expand Down
9 changes: 9 additions & 0 deletions Unit Tests/Test Classes/Dome Tests/DomeManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class DomeManagerTests
private const double _tolerance = 0.00001;

private DomeManager _mgr;

private MockDomeService _svc;
private int _startupDelayMs = 3000;

Expand All @@ -30,6 +31,7 @@ public void TestInit()
ServiceContainer.Instance.ClearAllServices();
ServiceContainer.Instance.AddService<IDomeService>( new MockDomeService() );
_mgr = DomeManager.Instance;

_svc = (MockDomeService)ServiceContainer.Instance.GetService<IDomeService>();

Messenger.Default.Register<DomeSlavedChangedMessage>( this, ( action ) => UpdateDomeSlavedState( action ) );
Expand All @@ -51,6 +53,7 @@ public void TestCleanup()
_mgr.Dispose();
}

#region Test Methods

[TestMethod]
public void Connect()
Expand Down Expand Up @@ -251,9 +254,15 @@ public void SetSlavedState()
Assert.IsFalse( Globals.IsDomeSlaved );
}

#endregion Test Methods

#region Helper Methods

private void UpdateDomeSlavedState( DomeSlavedChangedMessage action )
{
Globals.IsDomeSlaved = action.State;
}

#endregion Helper Methods
}
}
22 changes: 21 additions & 1 deletion Unit Tests/Test Classes/Telescope Tests/TelescopeManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public void TestCleanup()
_mgr.Dispose();
}

#region Test Methods

[TestMethod]
public void ConnectTest()
{
Expand Down Expand Up @@ -450,6 +452,24 @@ public void DestinationSideOfPierTest()
Assert.IsTrue( targetSOP == PierSide.pierEast );
}

[TestMethod]
[ExpectedException(typeof(NullReferenceException))]
public void NullAxisRatesTest()
{
Assert.IsTrue( _mgr.Connected );

TelescopeCapabilities caps = new TelescopeCapabilities( _mgr );
Assert.IsNotNull( caps );

_svc.MockNullPrimaryAxisRates = true;

caps = new TelescopeCapabilities( _mgr );

Assert.Fail( "No exception was thrown when receiving a null AxisRates list." );
}

#endregion Test Methods

#region Helper Methods

private Vector GetTargetRaDec()
Expand Down Expand Up @@ -526,6 +546,6 @@ private IRate[] GetAxisRateArrayFromService( TelescopeAxes axis )
return rateArr;
}

#endregion
#endregion Helper Methods
}
}

0 comments on commit 16b6d33

Please sign in to comment.