From c3a0de58149f4327b9cc93f99436438e7f000f9d Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 23 Feb 2023 12:02:51 -0800 Subject: [PATCH] [promises] Improve seq test (#32462) I had some doubts about `Seq` debugging another problem, so expanded the tests we have to try and isolate the problem (so far without success, so I think the original problem was elsewhere). --- src/core/lib/promise/detail/basic_seq.h | 2 +- test/core/promise/seq_test.cc | 36 +++++++++++++++++++------ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/core/lib/promise/detail/basic_seq.h b/src/core/lib/promise/detail/basic_seq.h index 513f5a6eae1..14899981fb8 100644 --- a/src/core/lib/promise/detail/basic_seq.h +++ b/src/core/lib/promise/detail/basic_seq.h @@ -168,7 +168,7 @@ auto CallNext(SeqState* state, T&& arg) &state->next_factory, std::forward(arg)); } -// A sequence under stome traits for some set of callables Fs. +// A sequence under some traits for some set of callables Fs. // Fs[0] should be a promise-like object that yields a value. // Fs[1..] should be promise-factory-like objects that take the value from the // previous step and yield a promise. Note that most of the machinery in diff --git a/test/core/promise/seq_test.cc b/test/core/promise/seq_test.cc index 61ae888599f..c64cf599035 100644 --- a/test/core/promise/seq_test.cc +++ b/test/core/promise/seq_test.cc @@ -14,6 +14,7 @@ #include "src/core/lib/promise/seq.h" +#include #include #include @@ -27,9 +28,21 @@ TEST(SeqTest, Immediate) { } TEST(SeqTest, OneThen) { - auto initial = [] { return 3; }; - auto then = [](int i) { return [i]() { return i + 4; }; }; - EXPECT_EQ(Seq(initial, then)(), Poll(7)); + auto initial = [a = std::make_unique(0)] { return 3; }; + auto then = [a = std::make_unique(1)](int i) { + return [i, b = std::make_unique(2)]() { return i + 4; }; + }; + EXPECT_EQ(Seq(std::move(initial), std::move(then))(), Poll(7)); +} + +TEST(SeqTest, OneThenIncomplete) { + auto initial = [a = std::make_unique(0)]() -> Poll { + return Pending{}; + }; + auto then = [a = std::make_unique(1)](int i) { + return [i, b = std::make_unique(2)]() { return i + 4; }; + }; + EXPECT_EQ(Seq(std::move(initial), std::move(then))(), Poll(Pending{})); } TEST(SeqTest, TwoTypedThens) { @@ -60,11 +73,18 @@ TEST(SeqTest, TwoThens) { } TEST(SeqTest, ThreeThens) { - EXPECT_EQ(Seq([] { return std::string("a"); }, - [](std::string i) { return [i]() { return i + "b"; }; }, - [](std::string i) { return [i]() { return i + "c"; }; }, - [](std::string i) { return [i]() { return i + "d"; }; })(), - Poll("abcd")); + EXPECT_EQ( + Seq([x = std::make_unique(1)] { return std::string("a"); }, + [x = std::make_unique(1)](std::string i) { + return [i, y = std::make_unique(2)]() { return i + "b"; }; + }, + [x = std::make_unique(1)](std::string i) { + return [i, y = std::make_unique(2)]() { return i + "c"; }; + }, + [x = std::make_unique(1)](std::string i) { + return [i, y = std::make_unique(2)]() { return i + "d"; }; + })(), + Poll("abcd")); } struct Big {