Unfortunately, this patch ends up very large, as the tests are almost entirely intertwined with one another, which makes splitting this change apart almost impossible.