Skip to content

Commit

Permalink
Add simulation of delay
Browse files Browse the repository at this point in the history
  • Loading branch information
rk0cc committed Jan 6, 2024
1 parent 874165d commit e00d704
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions model/lib/src/client.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:math' show Random;

import 'package:http/http.dart'
hide delete, get, head, patch, post, put, read, readBytes, runWithClient;
import 'package:http/testing.dart';
Expand Down Expand Up @@ -79,7 +81,8 @@ final class MockOgHrefClient extends MockClient implements OgHrefClient {
return Future.value(Response("", 400));
}

return Future<Response>.delayed(const Duration(milliseconds: 250), () {
return Future<Response>.delayed(
Duration(milliseconds: Random().nextInt(3000) + 250), () {
switch (int.parse(url.path.replaceAll(RegExp(r"[^0-9]"), ""))) {
case 1:
return Response(r"""
Expand Down Expand Up @@ -206,6 +209,8 @@ final class MockOgHrefClient extends MockClient implements OgHrefClient {
..headers["user-agent"] = OgHrefClient.userAgent
..followRedirects = redirect;

return super.send(request);
return super
.send(request)
.timeout(Duration(seconds: OgHrefClient.timeoutAt));
}
}

0 comments on commit e00d704

Please sign in to comment.