Added assertions to check conditions for exiting while loop

in _raisePermanenceToThreshold method

fixes #1322 
I should have said `Can we do this change in another PR' - sorry for the confusion.