Bug 11580 - Fix expiry calculation and rewrite tests