Skip to content

Commit

Permalink
Merge pull request #2450 from Aaronontheweb/fix-2449-asktimeoutspec
Browse files Browse the repository at this point in the history
 fixes race condition with AskTimeoutSpec
  • Loading branch information
Horusiath authored Jan 13, 2017
2 parents 4805420 + d0a6c9e commit ed27e03
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
14 changes: 11 additions & 3 deletions src/core/Akka.Tests/Actor/AskTimeoutSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,24 @@ public async Task TimedOut_ask_should_remove_temp_actor()
var actor = Sys.ActorOf<SleepyActor>();

var actorCell = actor as ActorRefWithCell;
Assert.NotNull(actorCell);

var container = actorCell.Provider.TempContainer as VirtualPathContainer;
Assert.NotNull(container);
try
{
await actor.Ask<string>("should time out");
}
catch (Exception)
{
var childCounter = 0;
container.ForEachChild(x => childCounter++);
Assert.True(childCounter==0,"Number of children in temp container should be 0.");
// Need to spin here, since the continuation function may not execute immediately
AwaitAssert(() =>
{
var childCounter = 0;
container.ForEachChild(x => childCounter++);
Assert.True(childCounter == 0, "Number of children in temp container should be 0.");
});

}

}
Expand Down
7 changes: 4 additions & 3 deletions src/core/Akka/Actor/ActorRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,8 @@ public override IActorRef GetChild(IEnumerable<string> name)
}

/// <summary>
/// TBD
/// Returns <c>true</c> if the <see cref="VirtualPathContainer"/> contains any children,
/// <c>false</c> otherwise.
/// </summary>
public bool HasChildren
{
Expand All @@ -837,9 +838,9 @@ public bool HasChildren
}

/// <summary>
/// TBD
/// Executes an action for each child in the current collection.
/// </summary>
/// <param name="action">TBD</param>
/// <param name="action">A lambda which takes a reference to the internal child actor as an argument.</param>
public void ForEachChild(Action<IInternalActorRef> action)
{
foreach (IInternalActorRef child in _children.Values)
Expand Down
2 changes: 1 addition & 1 deletion src/core/Akka/Actor/Futures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private static Task<object> Ask(ICanTell self, object message, IActorRefProvider
timeoutCancellation.Cancel();
timeoutCancellation.Dispose();
}
for (int i = 0; i < ctrList.Count; i++)
for (var i = 0; i < ctrList.Count; i++)
{
ctrList[i].Dispose();
}
Expand Down

0 comments on commit ed27e03

Please sign in to comment.