Fix PD not scaling down when waiting processes are terminated.

Also add a corresponding test