My understanding and what I have seen is that miles are deducted immediately at the time of the upgrade, even if you are waitlisted. This just occured the other day as I am waitlisted for two Intl Flights, the points were deducted at the time of the upgrade request but the upgrade was not finalized.
If the upgrade doesnt process then the miles are redeposited into your account, most likely after you take the flight which was not upgraded.