Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Tests/TestComponentCSharp/Class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,14 @@ namespace winrt::TestComponentCSharp::implementation
winrt::check_hresult(_asyncResult);
}

void Class::SetFailingCompletedHandler(IAsyncAction const& action)
{
action.Completed([](IAsyncAction const&, AsyncStatus)
{
throw winrt::hresult_error(E_FAIL, L"Intentional failure in completion handler");
});
}

IAsyncActionWithProgress<int32_t> Class::DoitAsyncWithProgress()
{
_asyncResult = E_PENDING;
Expand Down
2 changes: 2 additions & 0 deletions src/Tests/TestComponentCSharp/Class.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ namespace winrt::TestComponentCSharp::implementation
Windows::Foundation::IAsyncOperation<int32_t> AddAsync(int32_t lhs, int32_t rhs);
Windows::Foundation::IAsyncOperationWithProgress<int32_t, int32_t> AddAsyncWithProgress(int32_t lhs, int32_t rhs);

void SetFailingCompletedHandler(Windows::Foundation::IAsyncAction const& action);

Windows::Foundation::Point PointProperty();
void PointProperty(Windows::Foundation::Point const& value);
Windows::Foundation::Rect RectProperty();
Expand Down
2 changes: 2 additions & 0 deletions src/Tests/TestComponentCSharp/TestComponentCSharp.idl
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ namespace TestComponentCSharp
Windows.Foundation.IAsyncOperation<Int32> AddAsync(Int32 lhs, Int32 rhs);
Windows.Foundation.IAsyncOperationWithProgress<Int32, Int32> AddAsyncWithProgress(Int32 lhs, Int32 rhs);

void SetFailingCompletedHandler(Windows.Foundation.IAsyncAction action);

// Type mappings
// "Simple" structs (blittable with changes to add properties/functions/constructors/etc.)
Windows.Foundation.Point PointProperty;
Expand Down
19 changes: 19 additions & 0 deletions src/Tests/UnitTest/TestComponentCSharp_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4092,5 +4092,24 @@ public void TestNontProjectedClassAsBaseClass()
// Non projected class changes the behavior of the Value property to double it.
Assert.AreEqual(6, customEquals.Value);
}

[TestMethod]
public async Task TestFailingCompletionHandlerCrashesProcess()
{
// Create an IAsyncAction from a C# task that completes after 2 seconds.
var asyncAction = AsyncInfo.Run(_ => Task.Delay(TimeSpan.FromSeconds(2)));

// Pass it to native code which sets a Completed handler that throws.
var instance = new Class();
instance.SetFailingCompletedHandler(asyncAction);

// Wait long enough for the async action to complete and the native
// completion handler to fire. If the throwing handler crashes the
// process, we will never reach the assertion below.
await Task.Delay(TimeSpan.FromSeconds(5));

// If we get here, the process survived the throwing completion handler.
Assert.IsTrue(true, "Process survived the throwing native completion handler.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So like, if this test passes it means that either:

  • The test is somehow wrong
  • Something else is wrong 😆

@manodasanW this code should (intentionally) crash the process, right?

}
}
}
Loading