From ac07a0f0f43c9eb8f575aa4ac63b0735b66005e4 Mon Sep 17 00:00:00 2001 From: Aaron Stannard Date: Sat, 17 Apr 2021 14:49:04 -0500 Subject: [PATCH] harden Akka.DependencyInjection.Tests (#4945) Added some `AwaitAssert` calls to check for disposed dependencies - these calls can be racy due to background actor thread calling `Dipose` after foreground test thread checks the `Disposed` property. --- .../ActorServiceProviderPropsWithScopesSpecs.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/contrib/dependencyinjection/Akka.DependencyInjection.Tests/ActorServiceProviderPropsWithScopesSpecs.cs b/src/contrib/dependencyinjection/Akka.DependencyInjection.Tests/ActorServiceProviderPropsWithScopesSpecs.cs index 2f7f266ea3a..ef5d2fe0c39 100644 --- a/src/contrib/dependencyinjection/Akka.DependencyInjection.Tests/ActorServiceProviderPropsWithScopesSpecs.cs +++ b/src/contrib/dependencyinjection/Akka.DependencyInjection.Tests/ActorServiceProviderPropsWithScopesSpecs.cs @@ -45,7 +45,11 @@ public void ActorsWithScopedDependenciesShouldDisposeUponStop() ExpectTerminated(scoped1); // all dependencies should be disposed - deps1.Dependencies.All(x => x.Disposed).Should().BeTrue(); + AwaitAssert(() => + { + deps1.Dependencies.All(x => x.Disposed).Should().BeTrue(); + }); + // reuse the same props var scoped2 = Sys.ActorOf(props, "scoped2"); @@ -76,7 +80,10 @@ public void ActorsWithScopedDependenciesShouldDisposeAndRecreateUponRestart() }); // all previous dependencies should be disposed - deps1.Dependencies.All(x => x.Disposed).Should().BeTrue(); + AwaitAssert(() => + { + deps1.Dependencies.All(x => x.Disposed).Should().BeTrue(); + }); // actor should restart with totally new dependencies scoped1.Tell(new FetchDependencies()); @@ -104,7 +111,10 @@ public void ActorsWithMixedDependenciesShouldDisposeAndRecreateScopedUponRestart }); // all previous SCOPED dependencies should be disposed - deps1.Dependencies.Where(x => !(x is AkkaDiFixture.ISingletonDependency)).All(x => x.Disposed).Should().BeTrue(); + AwaitAssert(() => + { + deps1.Dependencies.Where(x => !(x is AkkaDiFixture.ISingletonDependency)).All(x => x.Disposed).Should().BeTrue(); + }); // singletons should not be disposed deps1.Dependencies.Where(x => (x is AkkaDiFixture.ISingletonDependency)).All(x => x.Disposed).Should().BeFalse();