1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
/*!
# tonic-mock
A comprehensive testing utility for [tonic](https://docs.rs/tonic) gRPC services in Rust.
This crate helps you test gRPC services with minimal effort by providing utilities to:
- Create and manipulate streaming requests and responses
- Process streaming responses with timeouts
- Test bidirectional streaming interactions
- Mock gRPC clients for isolated testing
- Add interceptors to modify requests
## Core Functionality
Seven main functions are provided:
- [`streaming_request`]: Build streaming requests based on a vector of messages.
- [`streaming_request_with_interceptor`]: Build streaming requests with an interceptor function.
- [`request_with_interceptor`]: Create a standard (non-streaming) request with an interceptor.
- [`process_streaming_response`]: Iterate the streaming response and call the closure user provided.
- [`process_streaming_response_with_timeout`]: Iterate the streaming response with a timeout for each message.
- [`stream_to_vec`]: Iterate the streaming response and generate a vector for further processing.
- [`stream_to_vec_with_timeout`]: Iterate the streaming response with a timeout and generate a vector.
Additionally, [`BidirectionalStreamingTest`] provides utilities for fine-grained testing of bidirectional streaming services,
and the [`client_mock`] module allows mocking gRPC clients.
## Basic Example
```rust
use tonic::{Request, Response, Status};
use tonic_mock::{streaming_request, process_streaming_response};
#[tokio::test]
async fn service_push_works() -> Result<(), Box<dyn std::error::Error>> {
// Create test data
let events = vec![
RequestPush::new("1", "data1"),
RequestPush::new("2", "data2"),
RequestPush::new("3", "data3"),
];
// Create a streaming request
let req = streaming_request(events);
// Call your service
let res = your_service.push(req).await?;
// Process the streaming response
process_streaming_response(res, |msg, i| {
assert!(msg.is_ok());
assert_eq!(msg.as_ref().unwrap().code, i as i32);
})
.await;
Ok(())
}
```
## Testing Client Streaming
For client streaming (multiple requests, single response), use [`streaming_request`] to create a stream of messages:
```rust
use tonic_mock::streaming_request;
// Create a vector of messages to send
let messages = vec![
StreamRequest { id: 1, data: "first".to_string() },
StreamRequest { id: 2, data: "second".to_string() },
];
// Create the streaming request
let request = streaming_request(messages);
// Call your service
let response = your_service.client_streaming_method(request).await?;
// Check the response
let response = response.into_inner();
assert_eq!(response.count, 2);
```
## Testing Server Streaming
For server streaming (single request, multiple responses), use [`process_streaming_response`] or [`stream_to_vec`]:
```rust
use tonic_mock::{process_streaming_response, stream_to_vec};
// Create the request
let request = Request::new(ServerStreamRequest { count: 3 });
// Call your service
let response = your_service.server_streaming_method(request).await?;
// Process responses with a callback
process_streaming_response(response, |msg, idx| {
assert!(msg.is_ok());
let response = msg.unwrap();
assert_eq!(response.index, idx as i32);
}).await;
// Or convert the stream to a vector
let request = Request::new(ServerStreamRequest { count: 3 });
let response = your_service.server_streaming_method(request).await?;
let results = stream_to_vec(response).await;
assert_eq!(results.len(), 3);
for (i, result) in results.iter().enumerate() {
assert!(result.is_ok());
let response = result.as_ref().unwrap();
assert_eq!(response.index, i as i32);
}
```
## Bidirectional Streaming
Use [`BidirectionalStreamingTest`] for testing bidirectional streaming services:
```rust
use std::time::Duration;
use tonic_mock::BidirectionalStreamingTest;
#[tokio::test]
async fn test_bidirectional_service() {
// Create a test context with your service function
let mut test = BidirectionalStreamingTest::new(my_bidirectional_service);
// Send messages one by one
test.send_client_message(TestRequest::new("msg1", "First message")).await;
// Get response
if let Some(response) = test.get_server_response().await {
// Verify response
assert_eq!(response.code, 200);
assert!(response.message.contains("First message"));
}
// You can also use timeouts
match test.get_server_response_with_timeout(Duration::from_millis(100)).await {
Ok(Some(resp)) => {
// Handle response
},
Ok(None) => {
// No more responses
},
Err(status) => {
// Timeout or other error
},
}
// Complete the test when done
test.complete().await;
}
```
## Mocking gRPC Clients
The [`client_mock`] module provides the [`MockableGrpcClient`] for mocking gRPC clients:
```rust
use tonic_mock::client_mock::{MockableGrpcClient, MockResponseDefinition, GrpcClientExt};
use tonic::{Request, Status, Code};
use prost::Message;
// Define a client type that will use the mock
#[derive(Clone)]
struct UserServiceClient<T> {
inner: T,
}
// Implement the GrpcClientExt trait for your client
impl GrpcClientExt<UserServiceClient<MockableGrpcClient>> for UserServiceClient<MockableGrpcClient> {
fn with_mock(mock: MockableGrpcClient) -> Self {
Self { inner: mock }
}
}
#[tokio::test]
async fn test_user_service_client() {
// Create a mock client
let mock = MockableGrpcClient::new();
// Configure mock responses
mock.mock::<UserRequest, UserResponse>("user.UserService", "GetUser")
.respond_when(
|req| req.user_id == "existing",
MockResponseDefinition::ok(UserResponse {
name: "Existing User".to_string(),
})
)
.await
.respond_with(
MockResponseDefinition::err(Status::new(Code::NotFound, "User not found"))
)
.await;
// Create a client with the mock
let mut client = UserServiceClient::with_mock(mock.clone());
// Make a request
let request = Request::new(UserRequest { user_id: "existing".to_string() });
let response = client.get_user(request).await.unwrap();
// Verify the response
assert_eq!(response.get_ref().name, "Existing User");
// Reset mock when done
mock.reset().await;
}
```
## Request Interceptors
Use interceptors to modify requests before they are sent:
```rust
use tonic::metadata::MetadataValue;
use tonic_mock::streaming_request_with_interceptor;
// Create a streaming request with an interceptor
let request = streaming_request_with_interceptor(messages, |req| {
// Add authentication header
req.metadata_mut().insert(
"authorization",
MetadataValue::from_static("Bearer token123")
);
// Add tracing header
req.metadata_mut().insert(
"x-request-id",
MetadataValue::from_static("trace-456")
);
});
```
## Timeout Support
Handle timeouts in streaming responses:
```rust
use std::time::Duration;
use tonic_mock::process_streaming_response_with_timeout;
// Process response with a 1-second timeout for each message
process_streaming_response_with_timeout(
response,
Duration::from_secs(1),
|msg, idx| {
if msg.is_ok() {
// Handle successful message
let response = msg.as_ref().unwrap();
} else {
// Handle error (could be timeout or other error)
let error = msg.as_ref().err().unwrap();
if error.code() == tonic::Code::DeadlineExceeded {
println!("Timeout occurred: {}", error.message());
}
}
}
).await;
```
## Test Utilities
The crate provides optional test utilities with the `test-utils` feature (enabled by default):
- [`TestRequest`] and [`TestResponse`]: Simple message types for testing
- [`create_test_messages`]: Generate test messages with sequential IDs
- [`create_stream_response`]: Create a streaming response from a vector of messages
- [`create_stream_response_with_errors`]: Create a streaming response with errors at specified indices
- [`assert_message_eq`]: Assert that a message matches expected values
- [`assert_response_eq`]: Assert that a response matches expected values
## gRPC Mock Utilities
The [`grpc_mock`] module provides low-level utilities for mocking gRPC messages:
- [`encode_grpc_request`](grpc_mock::encode_grpc_request): Encode a request message
- [`encode_grpc_response`](grpc_mock::encode_grpc_response): Encode a response message
- [`decode_grpc_message`](grpc_mock::decode_grpc_message): Decode a gRPC message
- [`mock_grpc_call`](grpc_mock::mock_grpc_call): Mock a gRPC call with a handler function
- [`create_grpc_uri`](grpc_mock::create_grpc_uri): Create a gRPC URI for a service method
*/
use ;
use Message;
use ;
use timeout;
use ;
pub use ;
pub use ;
pub use *;
/// Type alias for convenience
///
/// The inner type of a streaming response
pub type StreamResponseInner<T> = ;
/// Type alias for convenience
///
/// A streaming response from a mock service
pub type StreamResponse<T> = ;
/// Type alias for a request interceptor function
pub type RequestInterceptor<T> = ;
/// Generate streaming request for GRPC
///
/// When testing streaming RPC implemented with tonic, it is pretty clumsy
/// to build the streaming request, this function extracted test code and prost
/// decoder from tonic source code and wrap it with a nice interface. With it,
/// testing your streaming RPC implementation is much easier.
///
/// Usage:
/// ```
/// use bytes::Bytes;
/// use prost::Message;
/// use tonic_mock::streaming_request;
///
/// // normally this should be generated from protos with prost
/// #[derive(Clone, PartialEq, Message)]
/// pub struct Event {
/// #[prost(bytes = "bytes", tag = "1")]
/// pub id: Bytes,
/// #[prost(bytes = "bytes", tag = "2")]
/// pub data: Bytes,
/// }
///
/// let event = Event { id: Bytes::from("1"), data: Bytes::from("a".repeat(10)) };
/// let mut events = vec![event.clone(), event.clone(), event];
/// let stream = tonic_mock::streaming_request(events);
///
/// Generate streaming request for GRPC with an interceptor
///
/// This function is similar to `streaming_request` but allows specifying an interceptor
/// function that can modify the request before it's returned. This is useful for adding
/// metadata, headers, or other customizations to the request.
///
/// # Arguments
/// * `messages` - The vector of messages to include in the request
/// * `interceptor` - A function that can modify the request (e.g., to add metadata)
///
/// # Returns
/// A `Request<Streaming<T>>` with the interceptor applied
///
/// # Example
/// ```
/// use bytes::Bytes;
/// use prost::Message;
/// use tonic::{metadata::MetadataValue, Request};
/// use tonic_mock::streaming_request_with_interceptor;
///
/// #[derive(Clone, PartialEq, Message)]
/// pub struct Event {
/// #[prost(bytes = "bytes", tag = "1")]
/// pub id: Bytes,
/// #[prost(bytes = "bytes", tag = "2")]
/// pub data: Bytes,
/// }
///
/// let event = Event { id: Bytes::from("1"), data: Bytes::from("test") };
/// let events = vec![event.clone(), event.clone()];
///
/// // Create a request with an interceptor that adds metadata
/// let request = streaming_request_with_interceptor(events, |req| {
/// req.metadata_mut().insert(
/// "authorization",
/// MetadataValue::from_static("Bearer token123"),
/// );
/// req.metadata_mut().insert(
/// "x-request-id",
/// MetadataValue::from_static("test-request-id"),
/// );
/// });
///
/// // The request now has the metadata set by the interceptor
/// assert_eq!(
/// request.metadata().get("authorization").unwrap(),
/// "Bearer token123"
/// );
/// ```
/// Create a regular (non-streaming) request with an interceptor
///
/// This function creates a standard tonic Request and applies the provided interceptor
/// function to it. This is useful for adding metadata, headers, or other customizations
/// to regular (non-streaming) requests.
///
/// # Arguments
/// * `message` - The message to include in the request
/// * `interceptor` - A function that can modify the request (e.g., to add metadata)
///
/// # Returns
/// A `Request<T>` with the interceptor applied
///
/// # Example
/// ```
/// use bytes::Bytes;
/// use prost::Message;
/// use tonic::{metadata::MetadataValue, Request};
/// use tonic_mock::request_with_interceptor;
///
/// #[derive(Clone, PartialEq, Message)]
/// pub struct GetUserRequest {
/// #[prost(string, tag = "1")]
/// pub user_id: String,
/// }
///
/// let request_msg = GetUserRequest { user_id: "user123".to_string() };
///
/// // Create a request with an interceptor that adds metadata
/// let request = request_with_interceptor(request_msg, |req| {
/// req.metadata_mut().insert(
/// "authorization",
/// MetadataValue::from_static("Bearer token123"),
/// );
/// });
///
/// // The request now has the authorization metadata
/// assert_eq!(
/// request.metadata().get("authorization").unwrap(),
/// "Bearer token123"
/// );
/// ```
/// a simple wrapper to process and validate streaming response
///
/// Usage:
/// ```
/// use tonic::{Response, Status};
/// use futures::Stream;
/// use std::pin::Pin;
///
/// #[derive(Clone, PartialEq, ::prost::Message)]
/// pub struct ResponsePush {
/// #[prost(int32, tag = "1")]
/// pub code: i32,
/// }
///
/// // below code is to mimic a stream response from a GRPC service
/// let output = async_stream::try_stream! {
/// yield ResponsePush { code: 0 };
/// yield ResponsePush { code: 1 };
/// yield ResponsePush { code: 2 };
/// };
/// let response = Response::new(Box::pin(output) as tonic_mock::StreamResponseInner<ResponsePush>);
/// let rt = tokio::runtime::Runtime::new().unwrap();
///
/// // now we process the events
/// rt.block_on(async {
/// tonic_mock::process_streaming_response(response, |msg, i| {
/// assert!(msg.is_ok());
/// assert_eq!(msg.as_ref().unwrap().code, i as i32);
/// }).await;
/// });
/// ```
pub async
/// Process a streaming response with a configurable timeout
///
/// This function is similar to `process_streaming_response` but adds a timeout for each message.
/// If a message is not received within the specified timeout, the callback will be invoked with
/// a `Status::deadline_exceeded` error.
///
/// # Arguments
/// * `response` - The streaming response to process
/// * `timeout_duration` - The maximum time to wait for each message
/// * `f` - A callback function that receives each message result and its index
///
/// # Example
/// ```
/// use tonic::{Response, Status};
/// use futures::Stream;
/// use std::{pin::Pin, time::Duration};
///
/// #[derive(Clone, PartialEq, ::prost::Message)]
/// pub struct ResponsePush {
/// #[prost(int32, tag = "1")]
/// pub code: i32,
/// }
///
/// // below code is to mimic a stream response from a GRPC service
/// let output = async_stream::try_stream! {
/// yield ResponsePush { code: 0 };
/// yield ResponsePush { code: 1 };
/// yield ResponsePush { code: 2 };
/// };
/// let response = Response::new(Box::pin(output) as tonic_mock::StreamResponseInner<ResponsePush>);
/// let rt = tokio::runtime::Runtime::new().unwrap();
///
/// // now we process the events with a timeout
/// rt.block_on(async {
/// tonic_mock::process_streaming_response_with_timeout(
/// response,
/// Duration::from_secs(1),
/// |msg, i| {
/// assert!(msg.is_ok());
/// assert_eq!(msg.as_ref().unwrap().code, i as i32);
/// }
/// ).await;
/// });
/// ```
pub async
/// convert a streaming response to a Vec for simplified testing
///
/// Usage:
/// ```
/// use tonic::{Response, Status};
/// use futures::Stream;
/// use std::pin::Pin;
///
/// #[derive(Clone, PartialEq, ::prost::Message)]
/// pub struct ResponsePush {
/// #[prost(int32, tag = "1")]
/// pub code: i32,
/// }
///
/// // below code is to mimic a stream response from a GRPC service
/// let output = async_stream::try_stream! {
/// yield ResponsePush { code: 0 };
/// yield ResponsePush { code: 1 };
/// yield ResponsePush { code: 2 };
/// };
/// let response = Response::new(Box::pin(output) as tonic_mock::StreamResponseInner<ResponsePush>);
/// let rt = tokio::runtime::Runtime::new().unwrap();
///
/// // now we convert response to vec
/// let result: Vec<Result<ResponsePush, Status>> = rt.block_on(async { tonic_mock::stream_to_vec(response).await });
/// for (i, v) in result.iter().enumerate() {
/// assert!(v.is_ok());
/// assert_eq!(v.as_ref().unwrap().code, i as i32);
/// }
/// ```
pub async
/// Convert a streaming response to a Vec with timeout support
///
/// This function is similar to `stream_to_vec` but adds a timeout for each message.
/// If a message is not received within the specified timeout, a `Status::deadline_exceeded` error
/// will be added to the result vector and processing will stop.
///
/// # Arguments
/// * `response` - The streaming response to process
/// * `timeout_duration` - The maximum time to wait for each message
///
/// # Returns
/// A vector of message results, potentially including a timeout error
///
/// # Example
/// ```
/// use tonic::{Response, Status};
/// use futures::Stream;
/// use std::{pin::Pin, time::Duration};
///
/// #[derive(Clone, PartialEq, ::prost::Message)]
/// pub struct ResponsePush {
/// #[prost(int32, tag = "1")]
/// pub code: i32,
/// }
///
/// // below code is to mimic a stream response from a GRPC service
/// let output = async_stream::try_stream! {
/// yield ResponsePush { code: 0 };
/// yield ResponsePush { code: 1 };
/// yield ResponsePush { code: 2 };
/// };
/// let response = Response::new(Box::pin(output) as tonic_mock::StreamResponseInner<ResponsePush>);
/// let rt = tokio::runtime::Runtime::new().unwrap();
///
/// // now we convert response to vec with a timeout
/// let result = rt.block_on(async {
/// tonic_mock::stream_to_vec_with_timeout(response, Duration::from_secs(1)).await
/// });
/// for (i, v) in result.iter().enumerate() {
/// if i < 3 {
/// assert!(v.is_ok());
/// assert_eq!(v.as_ref().unwrap().code, i as i32);
/// }
/// }
/// ```
pub async
/// A bidirectional streaming test context that allows controlled message exchange
///
/// This utility provides a powerful way to test bidirectional streaming interactions
/// for gRPC services. It offers a simple interface for sending client messages to a service
/// and receiving server responses in a controlled manner.
///
/// # Key Features
///
/// - **Simplified Testing**: Test bidirectional streaming without complex setup
/// - **Controlled Message Flow**: Send messages and receive responses one by one
/// - **Timeout Support**: Set timeouts for receiving responses to test timing behavior
/// - **Clean Teardown**: Properly complete streams when testing is finished
///
/// # Usage Patterns
///
/// This utility supports two main usage patterns:
///
/// 1. **Sequential Pattern**: Send all messages, call complete(), then get all responses
/// 2. **Interactive Pattern**: Send all messages, call complete(), then get responses one by one
///
/// # Important Usage Notes
///
/// - You **MUST** call `complete()` before trying to get any responses
/// - For proper operation, send all client messages before calling `complete()`
/// - After calling `complete()`, you cannot send more messages
///
/// # Example
///
/// ```no_run
/// use std::time::Duration;
/// use tonic::{Request, Response, Status, Streaming};
/// use tonic_mock::{BidirectionalStreamingTest, StreamResponseInner, test_utils::TestRequest, test_utils::TestResponse};
///
/// # async fn example() {
/// // Define a simple echo service for testing
/// async fn echo_service(
/// request: Request<Streaming<TestRequest>>
/// ) -> Result<Response<StreamResponseInner<TestResponse>>, Status> {
/// let mut stream = request.into_inner();
/// let response_stream = async_stream::try_stream! {
/// while let Some(msg) = stream.message().await? {
/// let id_str = String::from_utf8_lossy(&msg.id).to_string();
/// yield TestResponse::new(200, format!("Echo: {}", id_str));
/// }
/// };
/// Ok(Response::new(Box::pin(response_stream)))
/// }
///
/// // Pattern 1: Send all messages, then get all responses
/// let mut test = BidirectionalStreamingTest::new(echo_service);
/// test.send_client_message(TestRequest::new("msg1", "data1")).await;
/// test.send_client_message(TestRequest::new("msg2", "data2")).await;
/// test.complete().await; // MUST call complete() before getting responses
///
/// let response1 = test.get_server_response().await;
/// let response2 = test.get_server_response().await;
///
/// // Pattern 2: Send all messages, then get responses one by one (interactive)
/// let mut test2 = BidirectionalStreamingTest::new(echo_service);
/// test2.send_client_message(TestRequest::new("msg1", "data1")).await;
/// test2.send_client_message(TestRequest::new("msg2", "data2")).await;
/// test2.complete().await; // MUST call complete() before getting responses
///
/// // Now get responses one by one
/// let response1 = test2.get_server_response().await;
/// println!("Got first response: {:?}", response1);
///
/// let response2 = test2.get_server_response().await;
/// println!("Got second response: {:?}", response2);
/// # }
/// ```