Skip to content

Commit

Permalink
Fixed one of the ContinueWith capture methods not capturing properly.
Browse files Browse the repository at this point in the history
Added missing ContinueWith capture tests.
Change cached expected progress value to uint from float.
  • Loading branch information
Tim committed Apr 22, 2020
1 parent 3a642fd commit 588732e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Promises/Internal/AllInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void IMultiTreeHandleable.ReAdd(PromisePassThrough passThrough)
partial class AllPromise0 : IInvokable
{
// These are used to avoid rounding errors when normalizing the progress.
private float _expected;
private uint _expected;
private UnsignedFixed32 _currentAmount;
private bool _invokingProgress;
private bool _suspended;
Expand Down
1 change: 1 addition & 0 deletions Promises/Internal/DelegateWrappersInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,7 @@ public sealed class DelegateContinueCaptureArgResult<TCapture, TArg, TResult> :
public static DelegateContinueCaptureArgResult<TCapture, TArg, TResult> GetOrCreate(TCapture capturedValue, Func<TCapture, Promise<TArg>.ResultContainer, TResult> callback)
{
var del = _pool.IsNotEmpty ? _pool.Pop() : new DelegateContinueCaptureArgResult<TCapture, TArg, TResult>();
del._capturedValue = capturedValue;
del._callback = callback;
return del;
}
Expand Down
2 changes: 1 addition & 1 deletion Promises/Internal/MergeInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void IMultiTreeHandleable.ReAdd(PromisePassThrough passThrough)
partial class MergePromise<T> : IInvokable
{
// These are used to avoid rounding errors when normalizing the progress.
private float _expected;
private uint _expected;
private UnsignedFixed32 _currentAmount;
private bool _invokingProgress;
private bool _suspended;
Expand Down
56 changes: 56 additions & 0 deletions Promises/Tests/CaptureTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,62 @@ public void OnContinueWillBeInvokedWithCapturedValue1()
LogAssert.NoUnexpectedReceived();
}

[Test]
public void OnContinueWillBeInvokedWithCapturedValue2()
{
var deferred = Promise.NewDeferred<int>();

string expected = "expected";
bool invoked = false;

TestHelper.AddContinueCallbacks<int, int, string>(deferred.Promise,
captureValue: expected,
onContinueCapture: (cv, r) =>
{
Assert.AreEqual(expected, cv);
invoked = true;
}
);

deferred.Resolve(50);
Promise.Manager.HandleCompletes();

Assert.AreEqual(true, invoked);

// Clean up.
GC.Collect();
Promise.Manager.HandleCompletesAndProgress();
LogAssert.NoUnexpectedReceived();
}

[Test]
public void OnContinueWillBeInvokedWithCapturedValue3()
{
var deferred = Promise.NewDeferred<int>();

string expected = "expected";
bool invoked = false;

TestHelper.AddContinueCallbacks<int, int, string>(deferred.Promise,
captureValue: expected,
onContinueCapture: (cv, r) =>
{
Assert.AreEqual(expected, cv);
invoked = true;
}
);

deferred.Reject("Reject");
Promise.Manager.HandleCompletes();

Assert.AreEqual(true, invoked);

// Clean up.
GC.Collect();
Promise.Manager.HandleCompletesAndProgress();
LogAssert.NoUnexpectedReceived();
}

[Test]
public void OnResolvedWillBeInvokedWithCapturedValue0()
{
Expand Down

0 comments on commit 588732e

Please sign in to comment.