File tree Expand file tree Collapse file tree 2 files changed +21
-10
lines changed Expand file tree Collapse file tree 2 files changed +21
-10
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,15 @@ void main() {
59
59
60
60
await pdb.close ();
61
61
62
+ // Give some time for connections to close
63
+ final watch = Stopwatch ()..start ();
64
+ while (server.connectionCount != 0 && watch.elapsedMilliseconds < 100 ) {
65
+ await Future .delayed (Duration (milliseconds: random.nextInt (10 )));
66
+ }
67
+
68
+ expect (server.connectionCount, equals (0 ));
69
+ expect (server.maxConnectionCount, lessThanOrEqualTo (1 ));
70
+
62
71
server.close ();
63
72
}
64
73
});
Original file line number Diff line number Diff line change @@ -11,7 +11,6 @@ import 'package:shelf_router/shelf_router.dart';
11
11
class TestServer {
12
12
late HttpServer server;
13
13
Router app = Router ();
14
- int connectionCount = 0 ;
15
14
int maxConnectionCount = 0 ;
16
15
int tokenExpiresIn;
17
16
@@ -27,19 +26,22 @@ class TestServer {
27
26
return 'http://${server .address .host }:${server .port }' ;
28
27
}
29
28
29
+ int get connectionCount {
30
+ return server.connectionsInfo ().total;
31
+ }
32
+
33
+ HttpConnectionsInfo connectionsInfo () {
34
+ return server.connectionsInfo ();
35
+ }
36
+
30
37
Future <Response > handleSyncStream (Request request) async {
31
- connectionCount += 1 ;
32
38
maxConnectionCount = max (connectionCount, maxConnectionCount);
33
39
34
40
stream () async * {
35
- try {
36
- var blob = "*" * 5000 ;
37
- for (var i = 0 ; i < 50 ; i++ ) {
38
- yield {"token_expires_in" : tokenExpiresIn, "blob" : blob};
39
- await Future .delayed (Duration (microseconds: 1 ));
40
- }
41
- } finally {
42
- connectionCount -= 1 ;
41
+ var blob = "*" * 5000 ;
42
+ for (var i = 0 ; i < 50 ; i++ ) {
43
+ yield {"token_expires_in" : tokenExpiresIn, "blob" : blob};
44
+ await Future .delayed (Duration (microseconds: 1 ));
43
45
}
44
46
}
45
47
You can’t perform that action at this time.
0 commit comments