fix: Race conditions in tests now that they are running faster
This commit is contained in:
parent
6a28ab05d0
commit
ec36d9c8fe
|
|
@ -16,6 +16,7 @@ void main() {
|
|||
Logs().level = Level.info;
|
||||
setUp(() async {
|
||||
matrix = await getClient();
|
||||
await matrix.abortSync();
|
||||
|
||||
voip = VoIP(matrix, MockWebRTCDelegate());
|
||||
VoIP.customTxid = '1234';
|
||||
|
|
|
|||
|
|
@ -45,11 +45,13 @@ void main() {
|
|||
final dbPath = join(Directory.current.path, 'test.sqlite');
|
||||
|
||||
setUp(() async {
|
||||
expect(await File(dbPath).exists(), false);
|
||||
expect(await File(dbPath).exists(), false,
|
||||
reason: '$dbPath should not exist');
|
||||
clientOnPath = await getClient(
|
||||
databasePath: dbPath,
|
||||
);
|
||||
expect(await File(dbPath).exists(), true);
|
||||
await clientOnPath.abortSync();
|
||||
expect(await File(dbPath).exists(), true, reason: '$dbPath should exist');
|
||||
});
|
||||
test('logout', () async {
|
||||
expect(await File(dbPath).exists(), true);
|
||||
|
|
@ -137,11 +139,12 @@ void main() {
|
|||
newOlmAccount: pickledOlmAccount,
|
||||
);
|
||||
|
||||
await Future.delayed(Duration(milliseconds: 50));
|
||||
|
||||
final loginState = await loginStateFuture;
|
||||
final sync = await syncFuture;
|
||||
|
||||
// to ensure our state doesn't get overwritten once we manually inject SyncUpdates
|
||||
await matrix.abortSync();
|
||||
|
||||
expect(loginState, LoginState.loggedIn);
|
||||
expect(matrix.onSync.value != null, true);
|
||||
expect(matrix.encryptionEnabled, true);
|
||||
|
|
@ -185,7 +188,7 @@ void main() {
|
|||
PresenceType.online);
|
||||
expect(presenceCounter, 1);
|
||||
expect(accountDataCounter, 10);
|
||||
await Future.delayed(Duration(milliseconds: 50));
|
||||
|
||||
expect(matrix.userDeviceKeys.keys.toSet(), {
|
||||
'@alice:example.com',
|
||||
'@othertest:fakeServer.notExisting',
|
||||
|
|
@ -1134,7 +1137,7 @@ void main() {
|
|||
newOlmAccount: pickledOlmAccount,
|
||||
);
|
||||
|
||||
await Future.delayed(Duration(milliseconds: 500));
|
||||
await client1.abortSync();
|
||||
|
||||
expect(client1.isLogged(), true);
|
||||
expect(client1.rooms.length, 3);
|
||||
|
|
@ -1146,7 +1149,8 @@ void main() {
|
|||
);
|
||||
|
||||
await client2.init();
|
||||
await Future.delayed(Duration(milliseconds: 500));
|
||||
|
||||
await client2.abortSync();
|
||||
|
||||
expect(client2.isLogged(), true);
|
||||
expect(client2.accessToken, client1.accessToken);
|
||||
|
|
@ -1197,6 +1201,7 @@ void main() {
|
|||
await client.getWellknown();
|
||||
expect(
|
||||
client.wellKnown?.mHomeserver.baseUrl.host, 'fakeserver.notexisting');
|
||||
await client.dispose();
|
||||
});
|
||||
|
||||
test('refreshAccessToken', () async {
|
||||
|
|
@ -1204,6 +1209,7 @@ void main() {
|
|||
expect(client.accessToken, 'abcd');
|
||||
await client.refreshAccessToken();
|
||||
expect(client.accessToken, 'a_new_token');
|
||||
await client.dispose();
|
||||
});
|
||||
|
||||
test('handleSoftLogout', () async {
|
||||
|
|
@ -1226,6 +1232,7 @@ void main() {
|
|||
storedClient?.tryGet<String>('refresh_token'),
|
||||
'another_new_token',
|
||||
);
|
||||
await client.dispose();
|
||||
});
|
||||
|
||||
test('object equality', () async {
|
||||
|
|
@ -1274,6 +1281,7 @@ void main() {
|
|||
final client = await getClient();
|
||||
client.backgroundSync = true;
|
||||
await client.clearCache();
|
||||
await client.dispose();
|
||||
});
|
||||
|
||||
test('dispose', () async {
|
||||
|
|
@ -1311,6 +1319,7 @@ void main() {
|
|||
await hiveClient.init();
|
||||
await Future.delayed(Duration(milliseconds: 200));
|
||||
expect(hiveClient.isLogged(), true);
|
||||
await hiveClient.dispose(closeDatabase: false);
|
||||
});
|
||||
|
||||
test('getEventByPushNotification', () async {
|
||||
|
|
@ -1402,6 +1411,8 @@ void main() {
|
|||
null,
|
||||
true,
|
||||
reason: '!5345234235:example.com not found as archived room');
|
||||
|
||||
await client.dispose();
|
||||
});
|
||||
|
||||
test(
|
||||
|
|
@ -1430,6 +1441,7 @@ void main() {
|
|||
expect(error.userId, '@user:server');
|
||||
expect(error.toString(), 'Exception: BAD_ACCOUNT_KEY');
|
||||
}
|
||||
await customClient.dispose(closeDatabase: true);
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ void main() {
|
|||
|
||||
test('setupClient', () async {
|
||||
client = await getClient();
|
||||
await client.abortSync();
|
||||
});
|
||||
|
||||
test('fromJson', () async {
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ void main() {
|
|||
await olm.init();
|
||||
olm.get_library_version();
|
||||
client = await getClient();
|
||||
await client.abortSync();
|
||||
});
|
||||
|
||||
test('basic things', () async {
|
||||
|
|
|
|||
|
|
@ -76,6 +76,8 @@ void main() {
|
|||
});
|
||||
test('Reply To Request', () async {
|
||||
final matrix = await getClient();
|
||||
await matrix.abortSync();
|
||||
|
||||
matrix.setUserId('@alice:example.com'); // we need to pretend to be alice
|
||||
FakeMatrixApi.calledEndpoints.clear();
|
||||
await matrix
|
||||
|
|
|
|||
|
|
@ -95,8 +95,13 @@ void main() async {
|
|||
KeyVerificationMethod.reciprocate
|
||||
};
|
||||
|
||||
// cancel sync to reduce background load and prevent sync overwriting which keys are tracked.
|
||||
await client1.abortSync();
|
||||
await client2.abortSync();
|
||||
|
||||
// get client2 device keys to start verification
|
||||
await client1.updateUserDeviceKeys(additionalUsers: {client2.userID!});
|
||||
await client2.updateUserDeviceKeys(additionalUsers: {client1.userID!});
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ Future<Client> getClient({
|
|||
newOlmAccount: pickledOlmAccount,
|
||||
);
|
||||
await Future.delayed(Duration(milliseconds: 10));
|
||||
await client.abortSync();
|
||||
return client;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ void main() {
|
|||
Logs().level = Level.error;
|
||||
test('Login', () async {
|
||||
matrix = await getClient();
|
||||
await matrix.abortSync();
|
||||
});
|
||||
|
||||
test('Create from json', () async {
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ void main() {
|
|||
client = await getClient(
|
||||
sendTimelineEventTimeout: const Duration(seconds: 5),
|
||||
);
|
||||
await client.abortSync();
|
||||
|
||||
final poison = Random().nextInt(2 ^ 32);
|
||||
currentPoison = poison;
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ void main() {
|
|||
await client.login(LoginType.mLoginPassword,
|
||||
identifier: AuthenticationUserIdentifier(user: 'test'),
|
||||
password: '1234');
|
||||
await client.abortSync();
|
||||
});
|
||||
tearDown(() async {
|
||||
await client.logout();
|
||||
|
|
|
|||
Loading…
Reference in New Issue