Addresses #1494 and #1495
Also some support code that was useful here and will probably be useful for other tests. This is a pretty complicated thing to test, but it seems to work.