Skip to content

Commit

Permalink
harden Akka.DependencyInjection.Tests (#4945)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Aaronontheweb authored Apr 17, 2021
1 parent e0f8604 commit ac07a0f
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit ac07a0f

Please sign in to comment.