@@ -702,7 +702,7 @@ func TestRunUnary(t *testing.T) {
702702 }
703703 }
704704
705- assert .Equal (t , []string {"0" , "__record_metadata__||token:secret2 " , "2" , "__record_metadata__||token:secret4 " , "4" }, names )
705+ assert .Equal (t , []string {"0" , "__record_metadata__||token:secret1 " , "2" , "__record_metadata__||token:secret3 " , "4" }, names )
706706 })
707707}
708708
@@ -1553,6 +1553,76 @@ func TestRunClientStreaming(t *testing.T) {
15531553 }
15541554 }
15551555 })
1556+
1557+ t .Run ("with stream message provider" , func (t * testing.T ) {
1558+ gs .ResetCounters ()
1559+
1560+ callCounter := 0
1561+
1562+ report , err := Run (
1563+ "helloworld.Greeter.SayHelloCS" ,
1564+ internal .TestLocalhost ,
1565+ WithProtoFile ("../testdata/greeter.proto" , []string {}),
1566+ WithTotalRequests (1 ),
1567+ WithConcurrency (1 ),
1568+ WithTimeout (time .Duration (20 * time .Second )),
1569+ WithDialTimeout (time .Duration (20 * time .Second )),
1570+ WithInsecure (true ),
1571+ WithStreamMessageProvider (func (cd * CallData ) (* dynamic.Message , error ) {
1572+ protoMsg := & helloworld.HelloRequest {Name : cd .WorkerID + ": " + strconv .Itoa (callCounter )}
1573+ dynamicMsg , err := dynamic .AsDynamicMessage (protoMsg )
1574+ if err != nil {
1575+ return nil , err
1576+ }
1577+
1578+ callCounter ++
1579+
1580+ if callCounter == 5 {
1581+ err = ErrLastMessage
1582+ }
1583+
1584+ return dynamicMsg , err
1585+ }),
1586+ )
1587+
1588+ assert .NoError (t , err )
1589+
1590+ assert .NotNil (t , report )
1591+
1592+ assert .NotZero (t , report .Total )
1593+ assert .Equal (t , 1 , int (report .Count ))
1594+ assert .NotZero (t , report .Average )
1595+ assert .NotZero (t , report .Fastest )
1596+ assert .NotZero (t , report .Slowest )
1597+ assert .NotZero (t , report .Rps )
1598+ assert .Empty (t , report .Name )
1599+ assert .NotEmpty (t , report .Date )
1600+ assert .NotEmpty (t , report .Details )
1601+ assert .NotEmpty (t , report .Options )
1602+ assert .Equal (t , true , report .Options .Insecure )
1603+ assert .NotEmpty (t , report .LatencyDistribution )
1604+ assert .Equal (t , ReasonNormalEnd , report .EndReason )
1605+ assert .Empty (t , report .ErrorDist )
1606+
1607+ assert .Equal (t , report .Average , report .Slowest )
1608+ assert .Equal (t , report .Average , report .Fastest )
1609+ assert .Equal (t , report .Slowest , report .Fastest )
1610+
1611+ count := gs .GetCount (callType )
1612+ assert .Equal (t , 1 , count )
1613+
1614+ connCount := gs .GetConnectionCount ()
1615+ assert .Equal (t , 1 , connCount )
1616+
1617+ calls := gs .GetCalls (callType )
1618+ assert .NotNil (t , calls )
1619+ assert .Len (t , calls , 1 )
1620+ msgs := calls [0 ]
1621+ assert .Len (t , msgs , 5 )
1622+
1623+ assert .Equal (t , "g0c0: 0" , msgs [0 ].GetName ())
1624+ assert .Equal (t , "g0c0: 4" , msgs [4 ].GetName ())
1625+ })
15561626}
15571627
15581628func TestRunClientStreamingBinary (t * testing.T ) {
@@ -2274,6 +2344,76 @@ func TestRunBidi(t *testing.T) {
22742344 msgs := calls [0 ]
22752345 assert .Len (t , msgs , 6 )
22762346 })
2347+
2348+ t .Run ("with stream message provider" , func (t * testing.T ) {
2349+ gs .ResetCounters ()
2350+
2351+ callCounter := 0
2352+
2353+ report , err := Run (
2354+ "helloworld.Greeter.SayHelloBidi" ,
2355+ internal .TestLocalhost ,
2356+ WithProtoFile ("../testdata/greeter.proto" , []string {}),
2357+ WithTotalRequests (1 ),
2358+ WithConcurrency (1 ),
2359+ WithTimeout (time .Duration (20 * time .Second )),
2360+ WithDialTimeout (time .Duration (20 * time .Second )),
2361+ WithInsecure (true ),
2362+ WithStreamMessageProvider (func (cd * CallData ) (* dynamic.Message , error ) {
2363+ protoMsg := & helloworld.HelloRequest {Name : cd .WorkerID + ": " + strconv .Itoa (callCounter )}
2364+ dynamicMsg , err := dynamic .AsDynamicMessage (protoMsg )
2365+ if err != nil {
2366+ return nil , err
2367+ }
2368+
2369+ callCounter ++
2370+
2371+ if callCounter == 7 {
2372+ err = ErrLastMessage
2373+ }
2374+
2375+ return dynamicMsg , err
2376+ }),
2377+ )
2378+
2379+ assert .NoError (t , err )
2380+
2381+ assert .NotNil (t , report )
2382+
2383+ assert .NotZero (t , report .Total )
2384+ assert .Equal (t , 1 , int (report .Count ))
2385+ assert .NotZero (t , report .Average )
2386+ assert .NotZero (t , report .Fastest )
2387+ assert .NotZero (t , report .Slowest )
2388+ assert .NotZero (t , report .Rps )
2389+ assert .Empty (t , report .Name )
2390+ assert .NotEmpty (t , report .Date )
2391+ assert .NotEmpty (t , report .Details )
2392+ assert .NotEmpty (t , report .Options )
2393+ assert .NotEmpty (t , report .LatencyDistribution )
2394+ assert .Equal (t , ReasonNormalEnd , report .EndReason )
2395+ assert .Equal (t , true , report .Options .Insecure )
2396+ assert .Empty (t , report .ErrorDist )
2397+
2398+ assert .Equal (t , report .Average , report .Slowest )
2399+ assert .Equal (t , report .Average , report .Fastest )
2400+ assert .Equal (t , report .Slowest , report .Fastest )
2401+
2402+ count := gs .GetCount (callType )
2403+ assert .Equal (t , 1 , count )
2404+
2405+ connCount := gs .GetConnectionCount ()
2406+ assert .Equal (t , 1 , connCount )
2407+
2408+ calls := gs .GetCalls (callType )
2409+ assert .NotNil (t , calls )
2410+ assert .Len (t , calls , 1 )
2411+ msgs := calls [0 ]
2412+ assert .Len (t , msgs , 7 )
2413+
2414+ assert .Equal (t , "g0c0: 0" , msgs [0 ].GetName ())
2415+ assert .Equal (t , "g0c0: 6" , msgs [6 ].GetName ())
2416+ })
22772417}
22782418
22792419func TestRunUnarySecure (t * testing.T ) {
0 commit comments