I'm trying to write some unit tests that verify that certain actors do not retain themselves upon being initialized. The first test I wrote was giving me intermittent results (if I run it 10 times it retains itself 5 times and does not retain itself the other 5 times), which I believe is due to the actor temporarily being retained by a task that will finish soon, but has not always finished by the time the unit test checks if the weak reference to the actor is now nil. Does anyone have any suggestions about a generally solid approach to this type of problem which guarantees that I avoid this type of unreliability in the unit test? I tried making the unit test async and then sleeping the test for 1 second to allow the tasks spawned by the actor to finish, but I still got intermittent results which led me to believe that perhaps I was inadvertently also sleeping the task which was retaining the actor. I messed around with detached tasks for a bit but nothing was seeming solid, which is why I'm turning to the forum for help. Thanks!
1 Like