@weston while it doesn’t solve the general class of problems you describe here, I have found that an adapted version of the helper described at https://paul-samuels.com/blog/2018/11/20/unit-testing-retain-cycles/ can help with some situations like this. Specifically, if the Task is holding strong references to something and therefore keeping it alive (likely if it is causing problems for you in your tests, I just ran into this recently), checking that that something is nil after the test will ensure that for practical purposes, you won’t have that problem.
Of course this doesn’t detect the more general issue of creating a Task with too long a lifetime or one that will keep executing forever doing nothing or with its results not being used for useful work. But it may help with your immediate issue — it definitely helped with my similar issue.