Skip to content

Commit fb86988

Browse files
committed
actor/test: extend TestAwaitFuture to cover fn.Err result path
In this commit, we extend TestAwaitFuture to cover the case where the future is completed with an fn.Err result. The existing test only exercised the fn.Ok (success) and context cancellation paths. The new case calls promise.Complete(fn.Err[string](sentinel)) directly and verifies that AwaitFuture surfaces the error as the second return value while returning the zero string value in the first, which is the documented contract for Result[T].Unpack().
1 parent 532a703 commit fb86988

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

actor/future_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,8 @@ func TestCompleteWith(t *testing.T) {
458458
}
459459

460460
// TestAwaitFuture verifies that AwaitFuture unpacks a resolved future into a
461-
// (value, nil) pair and that context cancellation before resolution is
461+
// (value, nil) pair, that a future completed with fn.Err is reported as a
462+
// (zero, err) pair, and that context cancellation before resolution is
462463
// reported as a (zero, ctx.Err()) pair.
463464
func TestAwaitFuture(t *testing.T) {
464465
t.Parallel()
@@ -471,6 +472,16 @@ func TestAwaitFuture(t *testing.T) {
471472
require.NoError(t, err)
472473
require.Equal(t, "hello", val)
473474

475+
// Future completed with fn.Err — should surface the error as the
476+
// second return value with the zero string value.
477+
sentinel := fmt.Errorf("result-level error")
478+
errPromise := NewPromise[string]()
479+
errPromise.Complete(fn.Err[string](sentinel))
480+
481+
val3, err3 := AwaitFuture(context.Background(), errPromise.Future())
482+
require.ErrorIs(t, err3, sentinel)
483+
require.Equal(t, "", val3, "zero value expected on fn.Err result")
484+
474485
// Cancelled context — should return the zero value and ctx.Err().
475486
unresolved := NewPromise[string]()
476487
ctx, cancel := context.WithCancel(context.Background())

0 commit comments

Comments
 (0)