Merge pull request #1815 from famedly/krille/make-request-timeout-configurable

refactor: Make network request timeout
This commit is contained in:
Krille-chan 2024-05-21 09:16:01 +02:00 committed by GitHub
commit 290cac25fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 17 additions and 12 deletions

View File

@ -81,8 +81,6 @@ class Client extends MatrixApi {
Set<String> supportedLoginTypes;
int sendMessageTimeoutSeconds;
bool requestHistoryOnLimitedTimeline;
final bool formatLocalpart;
@ -179,7 +177,8 @@ class Client extends MatrixApi {
Set<String>? roomPreviewLastEvents,
this.pinUnreadRooms = false,
this.pinInvitedRooms = true,
this.sendMessageTimeoutSeconds = 60,
@Deprecated('Use [sendTimelineEventTimeout] instead.')
int? sendMessageTimeoutSeconds,
this.requestHistoryOnLimitedTimeline = false,
Set<String>? supportedLoginTypes,
this.mxidLocalPartFallback = true,
@ -188,6 +187,7 @@ class Client extends MatrixApi {
NativeImplementations nativeImplementations = NativeImplementations.dummy,
Level? logLevel,
Filter? syncFilter,
Duration defaultNetworkRequestTimeout = const Duration(seconds: 35),
this.sendTimelineEventTimeout = const Duration(minutes: 1),
this.customImageResizer,
this.shareKeysWithUnverifiedDevices = true,
@ -221,7 +221,7 @@ class Client extends MatrixApi {
: nativeImplementations,
super(
httpClient: FixedTimeoutHttpClient(
httpClient ?? http.Client(), Duration(seconds: 35))) {
httpClient ?? http.Client(), defaultNetworkRequestTimeout)) {
if (logLevel != null) Logs().level = logLevel;
importantStateEvents.addAll([
EventTypes.RoomName,

View File

@ -123,7 +123,7 @@ class Event extends MatrixEvent {
originServerTs.millisecondsSinceEpoch;
final room = this.room;
if (age > room.client.sendMessageTimeoutSeconds * 1000) {
if (age > room.client.sendTimelineEventTimeout.inMilliseconds) {
// Update this event in database and open timelines
final json = toJson();
json['unsigned'] ??= <String, dynamic>{};

View File

@ -26,12 +26,14 @@ const ssssKey = 'EsT9 RzbW VhPW yqNp cC7j ViiW 5TZB LuY4 ryyv 9guN Ysmr WDPH';
const pickledOlmAccount =
'N2v1MkIFGcl0mQpo2OCwSopxPQJ0wnl7oe7PKiT4141AijfdTIhRu+ceXzXKy3Kr00nLqXtRv7kid6hU4a+V0rfJWLL0Y51+3Rp/ORDVnQy+SSeo6Fn4FHcXrxifJEJ0djla5u98fBcJ8BSkhIDmtXRPi5/oJAvpiYn+8zMjFHobOeZUAxYR0VfQ9JzSYBsSovoQ7uFkNks1M4EDUvHtuyg3RxViwdNxs3718fyAqQ/VSwbXsY0Nl+qQbF+nlVGHenGqk5SuNl1P6e1PzZxcR0IfXA94Xij1Ob5gDv5YH4UCn9wRMG0abZsQP0YzpDM0FLaHSCyo9i5JD/vMlhH+nZWrgAzPPCTNGYewNV8/h3c+VyJh8ZTx/fVi6Yq46Fv+27Ga2ETRZ3Qn+Oyx6dLBjnBZ9iUvIhqpe2XqaGA1PopOz8iDnaZitw';
Future<Client> getClient() async {
Future<Client> getClient(
{Duration sendTimelineEventTimeout = const Duration(minutes: 1)}) async {
final client = Client(
'testclient',
httpClient: FakeMatrixApi(),
databaseBuilder: getDatabase,
onSoftLogout: (client) => client.refreshAccessToken(),
sendTimelineEventTimeout: sendTimelineEventTimeout,
);
FakeMatrixApi.client = client;
await client.checkHomeserver(Uri.parse('https://fakeServer.notExisting'),

View File

@ -32,8 +32,9 @@ void main() {
late Client client;
setUp(() async {
client = await getClient();
client.sendMessageTimeoutSeconds = 5;
client = await getClient(
sendTimelineEventTimeout: const Duration(seconds: 5),
);
await client.abortSync();
insertList.clear();

View File

@ -62,8 +62,9 @@ void main() {
late Room room;
late Timeline timeline;
setUp(() async {
client = await getClient();
client.sendMessageTimeoutSeconds = 5;
client = await getClient(
sendTimelineEventTimeout: const Duration(seconds: 5),
);
room = Room(
id: roomID, client: client, prev_batch: 't123', roomAccountData: {});

View File

@ -64,8 +64,9 @@ void main() {
late Room room;
late Timeline timeline;
setUp(() async {
client = await getClient();
client.sendMessageTimeoutSeconds = 5;
client = await getClient(
sendTimelineEventTimeout: const Duration(seconds: 5),
);
final poison = Random().nextInt(2 ^ 32);
currentPoison = poison;