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() {
5959
6060 await pdb.close ();
6161
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+
6271 server.close ();
6372 }
6473 });
Original file line number Diff line number Diff line change @@ -11,7 +11,6 @@ import 'package:shelf_router/shelf_router.dart';
1111class TestServer {
1212 late HttpServer server;
1313 Router app = Router ();
14- int connectionCount = 0 ;
1514 int maxConnectionCount = 0 ;
1615 int tokenExpiresIn;
1716
@@ -27,19 +26,22 @@ class TestServer {
2726 return 'http://${server .address .host }:${server .port }' ;
2827 }
2928
29+ int get connectionCount {
30+ return server.connectionsInfo ().total;
31+ }
32+
33+ HttpConnectionsInfo connectionsInfo () {
34+ return server.connectionsInfo ();
35+ }
36+
3037 Future <Response > handleSyncStream (Request request) async {
31- connectionCount += 1 ;
3238 maxConnectionCount = max (connectionCount, maxConnectionCount);
3339
3440 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 ));
4345 }
4446 }
4547
You can’t perform that action at this time.
0 commit comments