diff --git a/test/core/end2end/cq_verifier.cc b/test/core/end2end/cq_verifier.cc index 503e2bba801..c84f5d1d3ac 100644 --- a/test/core/end2end/cq_verifier.cc +++ b/test/core/end2end/cq_verifier.cc @@ -187,26 +187,28 @@ std::string CqVerifier::ToString() const { return absl::StrJoin(expectations, "\n"); } -void CqVerifier::FailNoEventReceived() const { - gpr_log(GPR_ERROR, "no event received, but expected:%s", ToString().c_str()); +void CqVerifier::FailNoEventReceived(const SourceLocation& location) const { + gpr_log(GPR_ERROR, "[%s:%d] no event received, but expected:%s", + location.file(), location.line(), ToString().c_str()); abort(); } -void CqVerifier::FailUnexpectedEvent(grpc_event* ev) const { - gpr_log(GPR_ERROR, "cq returned unexpected event: %s", - grpc_event_string(ev).c_str()); +void CqVerifier::FailUnexpectedEvent(grpc_event* ev, + const SourceLocation& location) const { + gpr_log(GPR_ERROR, "[%s:%d] cq returned unexpected event: %s", + location.file(), location.line(), grpc_event_string(ev).c_str()); gpr_log(GPR_ERROR, "expected tags:\n%s", ToString().c_str()); abort(); } -void CqVerifier::Verify(Duration timeout) { +void CqVerifier::Verify(Duration timeout, SourceLocation location) { const gpr_timespec deadline = grpc_timeout_milliseconds_to_deadline(timeout.millis()); while (!expectations_.empty()) { grpc_event ev = grpc_completion_queue_next(cq_, deadline, nullptr); if (ev.type == GRPC_QUEUE_TIMEOUT) break; if (ev.type != GRPC_OP_COMPLETE) { - FailUnexpectedEvent(&ev); + FailUnexpectedEvent(&ev, location); } bool found = false; for (auto it = expectations_.begin(); it != expectations_.end(); ++it) { @@ -222,13 +224,13 @@ void CqVerifier::Verify(Duration timeout) { return true; }); if (!expected) { - FailUnexpectedEvent(&ev); + FailUnexpectedEvent(&ev, location); } expectations_.erase(it); found = true; break; } - if (!found) FailUnexpectedEvent(&ev); + if (!found) FailUnexpectedEvent(&ev, location); if (AllMaybes()) break; } expectations_.erase( @@ -237,7 +239,7 @@ void CqVerifier::Verify(Duration timeout) { return absl::holds_alternative(e.result); }), expectations_.end()); - if (!expectations_.empty()) FailNoEventReceived(); + if (!expectations_.empty()) FailNoEventReceived(location); } bool CqVerifier::AllMaybes() const { @@ -247,13 +249,13 @@ bool CqVerifier::AllMaybes() const { return true; } -void CqVerifier::VerifyEmpty(Duration timeout) { +void CqVerifier::VerifyEmpty(Duration timeout, SourceLocation location) { const gpr_timespec deadline = gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), timeout.as_timespec()); GPR_ASSERT(expectations_.empty()); grpc_event ev = grpc_completion_queue_next(cq_, deadline, nullptr); if (ev.type != GRPC_QUEUE_TIMEOUT) { - FailUnexpectedEvent(&ev); + FailUnexpectedEvent(&ev, location); } } diff --git a/test/core/end2end/cq_verifier.h b/test/core/end2end/cq_verifier.h index 3bf00c58bc1..5824f345029 100644 --- a/test/core/end2end/cq_verifier.h +++ b/test/core/end2end/cq_verifier.h @@ -57,10 +57,12 @@ class CqVerifier { // Ensure all expected events (and only those events) are present on the // bound completion queue within \a timeout. - void Verify(Duration timeout = Duration::Seconds(10)); + void Verify(Duration timeout = Duration::Seconds(10), + SourceLocation location = SourceLocation()); // Ensure that the completion queue is empty, waiting up to \a timeout. - void VerifyEmpty(Duration timeout = Duration::Seconds(1)); + void VerifyEmpty(Duration timeout = Duration::Seconds(1), + SourceLocation location = SourceLocation()); // Match an expectation about a status. // location must be DEBUG_LOCATION. @@ -80,8 +82,9 @@ class CqVerifier { std::string ToString() const; }; - void FailNoEventReceived() const; - void FailUnexpectedEvent(grpc_event* ev) const; + void FailNoEventReceived(const SourceLocation& location) const; + void FailUnexpectedEvent(grpc_event* ev, + const SourceLocation& location) const; bool AllMaybes() const; grpc_completion_queue* const cq_;