From 156e8bf617be6afa4cb3ba8b770713ead01616b1 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Mon, 9 Oct 2017 10:58:28 -0700 Subject: [PATCH] Make sure to accept expected tags exactly once --- test/cpp/end2end/async_end2end_test.cc | 32 +++++++++++++++----------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index f938aea40eb..a14b4d5295c 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -102,14 +102,23 @@ class Verifier { explicit Verifier(bool spin) : spin_(spin) {} // Expect sets the expected ok value for a specific tag Verifier& Expect(int i, bool expect_ok) { - expectations_[tag(i)] = expect_ok; + return ExpectUnless(i, expect_ok, false); + } + // ExpectUnless sets the expected ok value for a specific tag + // unless the tag was already marked seen (as a result of ExpectMaybe) + Verifier& ExpectUnless(int i, bool expect_ok, bool seen) { + if (!seen) { + expectations_[tag(i)] = expect_ok; + } return *this; } - // AcceptOnce sets the expected ok value for a specific tag, but does not + // ExpectMaybe sets the expected ok value for a specific tag, but does not // require it to appear // If it does, sets *seen to true - Verifier& AcceptOnce(int i, bool expect_ok, bool* seen) { - maybe_expectations_[tag(i)] = MaybeExpect{expect_ok, seen}; + Verifier& ExpectMaybe(int i, bool expect_ok, bool* seen) { + if (!*seen) { + maybe_expectations_[tag(i)] = MaybeExpect{expect_ok, seen}; + } return *this; } @@ -569,13 +578,13 @@ TEST_P(AsyncEnd2endTest, SimpleClientStreamingWithCoalescingApi) { Verifier(GetParam().disable_blocking) .Expect(2, true) - .AcceptOnce(3, true, &seen3) + .ExpectMaybe(3, true, &seen3) .Verify(cq_.get()); srv_stream.Read(&recv_request, tag(4)); Verifier(GetParam().disable_blocking) - .AcceptOnce(3, true, &seen3) + .ExpectUnless(3, true, seen3) .Expect(4, true) .Verify(cq_.get()); @@ -602,7 +611,6 @@ TEST_P(AsyncEnd2endTest, SimpleClientStreamingWithCoalescingApi) { EXPECT_EQ(send_response.message(), recv_response.message()); EXPECT_TRUE(recv_status.ok()); - EXPECT_TRUE(seen3); } // One ping, two pongs. @@ -853,13 +861,13 @@ TEST_P(AsyncEnd2endTest, SimpleBidiStreamingWithCoalescingApiWAF) { Verifier(GetParam().disable_blocking) .Expect(2, true) - .AcceptOnce(3, true, &seen3) + .ExpectMaybe(3, true, &seen3) .Verify(cq_.get()); srv_stream.Read(&recv_request, tag(4)); Verifier(GetParam().disable_blocking) - .AcceptOnce(3, true, &seen3) + .ExpectUnless(3, true, seen3) .Expect(4, true) .Verify(cq_.get()); EXPECT_EQ(send_request.message(), recv_request.message()); @@ -880,7 +888,6 @@ TEST_P(AsyncEnd2endTest, SimpleBidiStreamingWithCoalescingApiWAF) { Verifier(GetParam().disable_blocking).Expect(8, true).Verify(cq_.get()); EXPECT_TRUE(recv_status.ok()); - EXPECT_TRUE(seen3); } // One ping, one pong. Using server:WriteLast api @@ -910,13 +917,13 @@ TEST_P(AsyncEnd2endTest, SimpleBidiStreamingWithCoalescingApiWL) { Verifier(GetParam().disable_blocking) .Expect(2, true) - .AcceptOnce(3, true, &seen3) + .ExpectMaybe(3, true, &seen3) .Verify(cq_.get()); srv_stream.Read(&recv_request, tag(4)); Verifier(GetParam().disable_blocking) - .AcceptOnce(3, true, &seen3) + .ExpectUnless(3, true, seen3) .Expect(4, true) .Verify(cq_.get()); EXPECT_EQ(send_request.message(), recv_request.message()); @@ -939,7 +946,6 @@ TEST_P(AsyncEnd2endTest, SimpleBidiStreamingWithCoalescingApiWL) { Verifier(GetParam().disable_blocking).Expect(9, true).Verify(cq_.get()); EXPECT_TRUE(recv_status.ok()); - EXPECT_TRUE(seen3); } // Metadata tests