@@ -12,13 +12,27 @@ use tokio::sync::oneshot;
12
12
pub struct Server {
13
13
addr : net:: SocketAddr ,
14
14
panic_rx : std_mpsc:: Receiver < ( ) > ,
15
+ events_rx : std_mpsc:: Receiver < Event > ,
15
16
shutdown_tx : Option < oneshot:: Sender < ( ) > > ,
16
17
}
17
18
19
+ #[ non_exhaustive]
20
+ pub enum Event {
21
+ ConnectionClosed ,
22
+ }
23
+
18
24
impl Server {
19
25
pub fn addr ( & self ) -> net:: SocketAddr {
20
26
self . addr
21
27
}
28
+
29
+ pub fn events ( & mut self ) -> Vec < Event > {
30
+ let mut events = Vec :: new ( ) ;
31
+ while let Ok ( event) = self . events_rx . try_recv ( ) {
32
+ events. push ( event) ;
33
+ }
34
+ events
35
+ }
22
36
}
23
37
24
38
impl Drop for Server {
67
81
68
82
let ( shutdown_tx, mut shutdown_rx) = oneshot:: channel ( ) ;
69
83
let ( panic_tx, panic_rx) = std_mpsc:: channel ( ) ;
84
+ let ( events_tx, events_rx) = std_mpsc:: channel ( ) ;
70
85
let tname = format ! (
71
86
"test({})-support-server" ,
72
87
test_name,
@@ -92,8 +107,10 @@ where
92
107
async move { Ok :: <_, Infallible >( fut. await ) }
93
108
} ) ;
94
109
let builder = builder. clone( ) ;
110
+ let events_tx = events_tx. clone( ) ;
95
111
tokio:: spawn( async move {
96
112
let _ = builder. serve_connection_with_upgrades( hyper_util:: rt:: TokioIo :: new( io) , svc) . await ;
113
+ let _ = events_tx. send( Event :: ConnectionClosed ) ;
97
114
} ) ;
98
115
}
99
116
}
@@ -105,6 +122,7 @@ where
105
122
Server {
106
123
addr,
107
124
panic_rx,
125
+ events_rx,
108
126
shutdown_tx : Some ( shutdown_tx) ,
109
127
}
110
128
} )
@@ -152,6 +170,7 @@ where
152
170
153
171
let ( shutdown_tx, mut shutdown_rx) = oneshot:: channel ( ) ;
154
172
let ( panic_tx, panic_rx) = std_mpsc:: channel ( ) ;
173
+ let ( events_tx, events_rx) = std_mpsc:: channel ( ) ;
155
174
let tname = format ! (
156
175
"test({})-support-server" ,
157
176
test_name,
@@ -169,9 +188,11 @@ where
169
188
Some ( accepted) = endpoint. accept( ) => {
170
189
let conn = accepted. await . expect( "accepted" ) ;
171
190
let mut h3_conn = h3:: server:: Connection :: new( h3_quinn:: Connection :: new( conn) ) . await . unwrap( ) ;
191
+ let events_tx = events_tx. clone( ) ;
172
192
let func = func. clone( ) ;
173
193
tokio:: spawn( async move {
174
194
while let Ok ( Some ( ( req, stream) ) ) = h3_conn. accept( ) . await {
195
+ let events_tx = events_tx. clone( ) ;
175
196
let func = func. clone( ) ;
176
197
tokio:: spawn( async move {
177
198
let ( mut tx, rx) = stream. split( ) ;
@@ -198,6 +219,7 @@ where
198
219
}
199
220
}
200
221
tx. finish( ) . await . unwrap( ) ;
222
+ events_tx. send( Event :: ConnectionClosed ) . unwrap( ) ;
201
223
} ) ;
202
224
}
203
225
} ) ;
@@ -211,6 +233,7 @@ where
211
233
Server {
212
234
addr,
213
235
panic_rx,
236
+ events_rx,
214
237
shutdown_tx : Some ( shutdown_tx) ,
215
238
}
216
239
} )
0 commit comments