Added assertions to check conditions for exiting while loop

in _raisePermanenceToThreshold method

fixes #1322