Commit a0edcb03 authored by Marco Buttu's avatar Marco Buttu
Browse files

checkScan() and startScan() do not breake the goTo

In case of empty_scan, checkScan() and startScan() do not raise
an exception even if the system is not ready.
parent 6ad61276
Loading
Loading
Loading
Loading
+30 −8
Original line number Diff line number Diff line
@@ -55,12 +55,17 @@ class ScanBaseTest(unittest2.TestCase):
    def tearDown(self):
        if self.boss.isScanActive():
            t = self.boss.closeScan()
            self.waitUntil(t)
            self.waitUntilTime(t)

    def waitUntil(self, targetTime):
    def waitUntilTime(self, targetTime):
        while getTimeStamp().value < targetTime:
            time.sleep(0.1)

    def waitUntil(self, action, value):
        """For instance: waitUntil(isReady, True)"""
        while action() != value:
            time.sleep(0.1)
        

class ScanTest(ScanBaseTest):
    """Test checkScan(), startScan() and closeScan()"""
@@ -100,13 +105,23 @@ class ScanTest(ScanBaseTest):
                math.degrees(self.antennaInfo.elevation))
        self.centerScan = centerScanPosition[self.idx]

    def test_startScan_empty_scan(self):
        """Do nothing in case of empty scan"""
    def test_startScan_empty_scan_system_ready(self):
        """Do nothing in case of empty scan and system ready"""
        self.scan.is_empty_scan = True
        startTime = 0
        self.boss.startScan(startTime, self.scan, self.antennaInfo)
        self.assertFalse(self.boss.isScanActive())

    def test_startScan_empty_scan_system_not_ready(self):
        """Do nothing in case of empty scan and system NOT ready"""
        self.scan.is_empty_scan = True
        startTime = 0
        self.boss.park()
        self.waitUntil(self.boss.isReady, False)
        self.assertFalse(self.boss.isReady())
        self.boss.startScan(startTime, self.scan, self.antennaInfo)
        self.assertFalse(self.boss.isScanActive())

    def test_startScan_ASAP(self):
        """Starting time unknown: the scan must start ASAP"""
        startTime = 0
@@ -154,7 +169,7 @@ class ScanTest(ScanBaseTest):
        """Return the time_to_stop"""
        startTime = 0
        t = self.boss.startScan(startTime, self.scan, self.antennaInfo)
        self.waitUntil(startTime)
        self.waitUntilTime(startTime)
        time_to_stop = self.boss.closeScan()
        # The time_to_stop should be greater than now
        self.assertGreater(time_to_stop, getTimeStamp().value) 
@@ -239,7 +254,7 @@ class ScanTest(ScanBaseTest):
        self.assertFalse(self.boss.isScanning())
        self.assertTrue(self.boss.isScanActive())
        # Assertions to verify right after startTime
        self.waitUntil(startTime)
        self.waitUntilTime(startTime)
        self.assertTrue(self.boss.isScanning())
        self.assertTrue(self.boss.isScanActive())
        self.assertAlmostEqual(
@@ -248,7 +263,7 @@ class ScanTest(ScanBaseTest):
                delta=0.1)
        # Wait untill the scan finishes (one second after the scan)
        targetTime = startTime + self.scan.total_time + 1*10**7 
        self.waitUntil(targetTime)
        self.waitUntilTime(targetTime)
        startPos = self.boss.getAxesPosition(startTime)[self.idx]
        endPos = self.boss.getAxesPosition(targetTime)[self.idx]
        self.assertTrue(self.boss.isScanActive())
@@ -345,11 +360,18 @@ class ScanTest(ScanBaseTest):
class ScanInterfaceTest(ScanBaseTest):
    """Test the interface of startScan() and closeScan()"""

    def test_checkScan_system_not_ready(self):
    def test_checkScan_not_empty_system_not_ready(self):
        """Raise a MinorServoErrorsEx in case the system is not ready"""
        with self.assertRaises(MinorServoErrorsEx):
            t = self.boss.checkScan(0, self.scan, self.antennaInfo) 

    def test_checkScan_empty_scan_system_not_ready(self):
        """Do nothing in case of empty scan and system NOT ready"""
        self.scan.is_empty_scan = True
        self.assertFalse(self.boss.isReady())
        t = self.boss.checkScan(0, self.scan, self.antennaInfo)
        self.assertFalse(self.boss.isScanActive())

    def test_closeScan_scan_not_active(self):
        """Do nothing in case no scan is active"""
        self.boss.closeScan() 
+24 −18
Original line number Diff line number Diff line
@@ -722,6 +722,19 @@ CORBA::Boolean MinorServoBossImpl::checkScan(
        MinorServo::TRunTimeParameters_out msParameters
    ) throw (MinorServoErrors::MinorServoErrorsEx, ComponentErrors::ComponentErrorsEx)
{
    MinorServo::TRunTimeParameters_var msParamVar = new MinorServo::TRunTimeParameters;

    msParamVar->onTheFly = false;
    msParamVar->startEpoch = 0;
    msParamVar->centerScan = 0;
    msParamVar->scanAxis = CORBA::string_dup("");
    msParamVar->timeToStop = 0;
    msParameters = msParamVar._retn();

    if(msScanInfo.is_empty_scan == true && !isReady()) {
        return true;
    }

    if(!isReady()) {
        string msg("checkScan(): the system is not ready");
        _EXCPT(MinorServoErrors::StatusErrorExImpl, impl, msg.c_str());
@@ -735,14 +748,7 @@ CORBA::Boolean MinorServoBossImpl::checkScan(
        impl.log(LM_DEBUG);
        throw impl.getMinorServoErrorsEx();
    }
    MinorServo::TRunTimeParameters_var msParamVar = new MinorServo::TRunTimeParameters;

    msParamVar->onTheFly = false;
    msParamVar->startEpoch = 0;
    msParamVar->centerScan = 0;
    msParamVar->scanAxis = CORBA::string_dup("");
    msParamVar->timeToStop = 0;
    msParameters = msParamVar._retn();
    try {
        return checkScanImpl(startingTime, msScanInfo, antennaInfo, msParameters);
    }
@@ -1137,6 +1143,12 @@ void MinorServoBossImpl::startScan(
        const Antenna::TRunTimeParameters & antennaInfo
    ) throw (MinorServoErrors::MinorServoErrorsEx, ComponentErrors::ComponentErrorsEx)
{

    if(msScanInfo.is_empty_scan) {
        startingTime = getTimeStamp();
        return ;
    }

    if(!isReady()) {
        string msg("startScan(): the system is not ready");
        _EXCPT(MinorServoErrors::StatusErrorExImpl, impl, msg.c_str());
@@ -1151,18 +1163,12 @@ void MinorServoBossImpl::startScan(
        throw impl.getMinorServoErrorsEx();
    }

    if(msScanInfo.is_empty_scan) {
        startingTime = getTimeStamp();
        return ;
    }
    else {
    startScanImpl(
            startingTime, 
            msScanInfo,
            antennaInfo
    );
}
}


void MinorServoBossImpl::startScanImpl(