Stressful environments can indirectly select for increased longevity