@ -24,6 +24,7 @@
# include <algorithm>
# include <initializer_list>
# include <limits>
# include <string>
# include <utility>
# include <vector>
@ -182,7 +183,9 @@ int byte_buffer_eq_string(grpc_byte_buffer* bb, const char* str) {
namespace {
bool IsProbablyInteger ( void * p ) {
return reinterpret_cast < uintptr_t > ( p ) < 1000000 ;
return reinterpret_cast < uintptr_t > ( p ) < 1000000 | |
( reinterpret_cast < uintptr_t > ( p ) >
std : : numeric_limits < uintptr_t > : : max ( ) - 10 ) ;
}
std : : string TagStr ( void * tag ) {
@ -224,6 +227,21 @@ std::string CqVerifier::Expectation::ToString() const {
} ) ) ;
}
std : : string CqVerifier : : Expectation : : ToShortString ( ) const {
return absl : : StrCat (
TagStr ( tag ) ,
Match (
result ,
[ ] ( bool success ) - > std : : string {
if ( ! success ) return " -❌ " ;
return " -✅ " ;
} ,
[ ] ( Maybe ) { return std : : string ( " -❓ " ) ; } ,
[ ] ( AnyStatus ) { return std : : string ( " -🤷 " ) ; } ,
[ ] ( const PerformAction & ) { return std : : string ( " -🎬 " ) ; } ,
[ ] ( const MaybePerformAction & ) { return std : : string ( " -🎬❓ " ) ; } ) ) ;
}
std : : vector < std : : string > CqVerifier : : ToStrings ( ) const {
std : : vector < std : : string > expectations ;
expectations . reserve ( expectations_ . size ( ) ) ;
@ -237,6 +255,19 @@ std::string CqVerifier::ToString() const {
return absl : : StrJoin ( ToStrings ( ) , " \n " ) ;
}
std : : vector < std : : string > CqVerifier : : ToShortStrings ( ) const {
std : : vector < std : : string > expectations ;
expectations . reserve ( expectations_ . size ( ) ) ;
for ( const auto & e : expectations_ ) {
expectations . push_back ( e . ToShortString ( ) ) ;
}
return expectations ;
}
std : : string CqVerifier : : ToShortString ( ) const {
return absl : : StrJoin ( ToShortStrings ( ) , " " ) ;
}
void CqVerifier : : FailNoEventReceived ( const SourceLocation & location ) const {
fail_ ( Failure { location , " No event received " , ToStrings ( ) } ) ;
}
@ -248,7 +279,8 @@ void CqVerifier::FailUnexpectedEvent(grpc_event* ev,
ToStrings ( ) } ) ;
}
void CqVerifier : : FailUsingGprCrash ( const Failure & failure ) {
namespace {
std : : string CrashMessage ( const CqVerifier : : Failure & failure ) {
std : : string message =
absl : : StrCat ( failure . message , " \n expectation checked @ " ,
failure . location . file ( ) , " : " , failure . location . line ( ) ) ;
@ -260,7 +292,16 @@ void CqVerifier::FailUsingGprCrash(const Failure& failure) {
} else {
absl : : StrAppend ( & message , " \n expected nothing " ) ;
}
CrashWithStdio ( message ) ;
return message ;
}
} // namespace
void CqVerifier : : FailUsingGprCrashWithStdio ( const Failure & failure ) {
CrashWithStdio ( CrashMessage ( failure ) ) ;
}
void CqVerifier : : FailUsingGprCrash ( const Failure & failure ) {
Crash ( CrashMessage ( failure ) ) ;
}
void CqVerifier : : FailUsingGtestFail ( const Failure & failure ) {
@ -302,6 +343,9 @@ grpc_event CqVerifier::Step(gpr_timespec deadline) {
}
void CqVerifier : : Verify ( Duration timeout , SourceLocation location ) {
if ( expectations_ . empty ( ) ) return ;
gpr_log ( GPR_ERROR , " Verify %s for %s " , ToShortString ( ) . c_str ( ) ,
timeout . ToString ( ) . c_str ( ) ) ;
const gpr_timespec deadline =
grpc_timeout_milliseconds_to_deadline ( timeout . millis ( ) ) ;
while ( ! expectations_ . empty ( ) ) {
@ -358,6 +402,8 @@ bool CqVerifier::AllMaybes() const {
}
void CqVerifier : : VerifyEmpty ( Duration timeout , SourceLocation location ) {
gpr_log ( GPR_ERROR , " Verify empty completion queue for %s " ,
timeout . ToString ( ) . c_str ( ) ) ;
const gpr_timespec deadline =
gpr_time_add ( gpr_now ( GPR_CLOCK_MONOTONIC ) , timeout . as_timespec ( ) ) ;
GPR_ASSERT ( expectations_ . empty ( ) ) ;