[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).
<!--

If you know who should review your pull request, please assign it to
that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the
appropriate
lang label.

-->
pull/32465/head
Craig Tiller 2 years ago committed by GitHub
parent 151399183f
commit c3a0de5814
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/core/lib/promise/detail/basic_seq.h
  2. 36
      test/core/promise/seq_test.cc

@ -168,7 +168,7 @@ auto CallNext(SeqState<Traits, I, Fs...>* state, T&& arg)
&state->next_factory, std::forward<T>(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

@ -14,6 +14,7 @@
#include "src/core/lib/promise/seq.h"
#include <memory>
#include <string>
#include <vector>
@ -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<int>(7));
auto initial = [a = std::make_unique<int>(0)] { return 3; };
auto then = [a = std::make_unique<int>(1)](int i) {
return [i, b = std::make_unique<int>(2)]() { return i + 4; };
};
EXPECT_EQ(Seq(std::move(initial), std::move(then))(), Poll<int>(7));
}
TEST(SeqTest, OneThenIncomplete) {
auto initial = [a = std::make_unique<int>(0)]() -> Poll<int> {
return Pending{};
};
auto then = [a = std::make_unique<int>(1)](int i) {
return [i, b = std::make_unique<int>(2)]() { return i + 4; };
};
EXPECT_EQ(Seq(std::move(initial), std::move(then))(), Poll<int>(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<std::string>("abcd"));
EXPECT_EQ(
Seq([x = std::make_unique<int>(1)] { return std::string("a"); },
[x = std::make_unique<int>(1)](std::string i) {
return [i, y = std::make_unique<int>(2)]() { return i + "b"; };
},
[x = std::make_unique<int>(1)](std::string i) {
return [i, y = std::make_unique<int>(2)]() { return i + "c"; };
},
[x = std::make_unique<int>(1)](std::string i) {
return [i, y = std::make_unique<int>(2)]() { return i + "d"; };
})(),
Poll<std::string>("abcd"));
}
struct Big {

Loading…
Cancel
Save