[PH2][Test][Transport] Adding missing test to party_test.cc (#38818)

[PH2][Test][Transport] Adding missing test to party_test.cc

This test asserts that the on_complete function of the Spawn should be called even if the first promise returns failing status.

Closes #38818

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/38818 from tanvi-jagtap:missing_unit_test 789f19a964
PiperOrigin-RevId: 730883583
pull/38725/merge
Tanvi Jagtap - Google LLC 2 days ago committed by Copybara-Service
parent ca0d85cea5
commit 070e6fcf40
  1. 3
      src/core/lib/promise/party.h
  2. 22
      test/core/promise/party_test.cc

@ -305,7 +305,8 @@ class Party : public Activity, private Wakeable {
// The party can poll the promise until it is resolved, or until the party is
// shut down.
// The on_complete callback will be called with the result of the
// promise if it completes.
// promise if it completes. Even if the promise returns a failed status,
// on_complete will be called.
// promise_factory called to create the promise with the party lock taken;
// after the promise is created the factory is destroyed. This means that
// pointers or references to factory members will be invalidated after the

@ -110,6 +110,28 @@ TEST_F(PartyTest, SpawnAndRunOneParty) {
VLOG(2) << "Execution order : " << execution_order;
}
TEST_F(PartyTest, SpawnAndFail) {
// Assert that on_complete function of the Spawn should be called
// even if the Spawned promise returns failing status.
std::string execution_order;
auto party = MakeParty();
Notification n;
party->Spawn(
"TestSpawn",
[&execution_order]() mutable -> absl::StatusOr<int> {
absl::StrAppend(&execution_order, "1");
return absl::CancelledError();
},
[&n, &execution_order](absl::StatusOr<int> x) {
absl::StrAppend(&execution_order, "2");
n.Notify();
});
n.WaitForNotification();
absl::StrAppend(&execution_order, "3");
EXPECT_STREQ(execution_order.c_str(), "123");
VLOG(2) << "Execution order : " << execution_order;
}
auto MakePromise(std::string& execution_order, int num) {
return [i = num, &execution_order]() mutable -> Poll<int> {
absl::StrAppend(&execution_order, "L");

Loading…
Cancel
Save