From e266ef7312784136438b7b0993f4ed0f98e87358 Mon Sep 17 00:00:00 2001 From: Krille Date: Fri, 22 Mar 2024 15:56:57 +0100 Subject: [PATCH] refactor: Switch to MatrixSdkDatabase as suggested database and deprecate other ones --- .github/workflows/app.yml | 2 +- lib/src/database/hive_collections_database.dart | 2 ++ lib/src/database/hive_database.dart | 2 +- pubspec.yaml | 2 +- scripts/integration-prepare-alpine.sh | 2 +- test/client_test.dart | 6 +++++- test/fake_database.dart | 9 +++++++-- test/fake_matrix_api.dart | 2 +- test/room_test.dart | 2 +- 9 files changed, 20 insertions(+), 9 deletions(-) diff --git a/.github/workflows/app.yml b/.github/workflows/app.yml index 377de5b1..ceba9223 100644 --- a/.github/workflows/app.yml +++ b/.github/workflows/app.yml @@ -60,7 +60,7 @@ jobs: sdk: ${{ env.dart_version }} - name: Run tests run: | - apt-get update && apt-get install --no-install-recommends --no-install-suggests -y curl lcov python3 python3-distutils libsqlite3-dev + apt-get update && apt-get install --no-install-recommends --no-install-suggests -y curl lcov python3 python3-distutils libsqlite3-0 libsqlite3-dev curl -o /bin/lcov_cobertura.py https://raw.githubusercontent.com/eriwen/lcov-to-cobertura-xml/master/lcov_cobertura/lcov_cobertura.py && sed 's/env python/env python3/' -i /bin/lcov_cobertura.py && chmod +x /bin/lcov_cobertura.py dart pub get ./scripts/test.sh diff --git a/lib/src/database/hive_collections_database.dart b/lib/src/database/hive_collections_database.dart index 06c2847d..e583e4df 100644 --- a/lib/src/database/hive_collections_database.dart +++ b/lib/src/database/hive_collections_database.dart @@ -34,6 +34,8 @@ import 'package:matrix/src/utils/queued_to_device_event.dart'; import 'package:matrix/src/utils/run_benchmarked.dart'; /// This database does not support file caching! +@Deprecated( + 'Use [MatrixSdkDatabase] instead. Don\'t forget to properly migrate!') class HiveCollectionsDatabase extends DatabaseApi { static const int version = 7; final String name; diff --git a/lib/src/database/hive_database.dart b/lib/src/database/hive_database.dart index 45134e27..b6e29dd0 100644 --- a/lib/src/database/hive_database.dart +++ b/lib/src/database/hive_database.dart @@ -39,7 +39,7 @@ import 'package:matrix/src/utils/run_benchmarked.dart'; /// /// This database does not support file caching! @Deprecated( - 'Use [HiveCollectionsDatabase] instead. Don\'t forget to properly migrate!') + 'Use [MatrixSdkDatabase] instead. Don\'t forget to properly migrate!') class FamedlySdkHiveDatabase extends DatabaseApi with ZoneTransactionMixin { static const int version = 6; final String name; diff --git a/pubspec.yaml b/pubspec.yaml index 3d25c302..c70224bc 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -39,7 +39,7 @@ dev_dependencies: file: ">=6.1.1 <8.0.0" import_sorter: ^4.6.0 lints: ^3.0.0 - sqflite_common_ffi: ^2.2.5 + sqflite_common_ffi: ^2.3.3 test: ^1.15.7 #flutter_test: {sdk: flutter} #dependency_overrides: diff --git a/scripts/integration-prepare-alpine.sh b/scripts/integration-prepare-alpine.sh index f3f10b41..6c2fbde3 100755 --- a/scripts/integration-prepare-alpine.sh +++ b/scripts/integration-prepare-alpine.sh @@ -1,2 +1,2 @@ #!/usr/bin/env bash -apk update && apk add docker drill grep olm cmake \ No newline at end of file +apk update && apk add docker drill grep olm cmake sqlite-dev \ No newline at end of file diff --git a/test/client_test.dart b/test/client_test.dart index bcbc5e0f..9e31cced 100644 --- a/test/client_test.dart +++ b/test/client_test.dart @@ -155,7 +155,11 @@ void main() { expect(presenceCounter, 1); expect(accountDataCounter, 10); await Future.delayed(Duration(milliseconds: 50)); - expect(matrix.userDeviceKeys.length, 4); + expect(matrix.userDeviceKeys.keys.toSet(), { + '@alice:example.com', + '@othertest:fakeServer.notExisting', + '@test:fakeServer.notExisting', + }); expect(matrix.userDeviceKeys['@alice:example.com']?.outdated, false); expect(matrix.userDeviceKeys['@alice:example.com']?.deviceKeys.length, 2); expect( diff --git a/test/fake_database.dart b/test/fake_database.dart index 2d041e62..becc3add 100644 --- a/test/fake_database.dart +++ b/test/fake_database.dart @@ -22,10 +22,11 @@ import 'package:sqflite_common_ffi/sqflite_ffi.dart'; import 'package:matrix/matrix.dart'; -Future getDatabase(Client? _) => getHiveCollectionsDatabase(_); +Future getDatabase(Client? _) => getMatrixSdkDatabase(_); bool hiveInitialized = false; +// ignore: deprecated_member_use_from_same_package Future getHiveCollectionsDatabase(Client? c) async { final testHivePath = await LocalFileSystem() .systemTempDirectory @@ -33,6 +34,7 @@ Future getHiveCollectionsDatabase(Client? c) async { if (!hiveInitialized) { Hive.init(testHivePath.path); } + // ignore: deprecated_member_use_from_same_package final db = HiveCollectionsDatabase( 'unit_test.${c?.hashCode}', testHivePath.path, @@ -43,7 +45,10 @@ Future getHiveCollectionsDatabase(Client? c) async { // ignore: deprecated_member_use_from_same_package Future getMatrixSdkDatabase(Client? c) async { - final database = await databaseFactoryFfi.openDatabase(':memory:'); + final database = await databaseFactoryFfi.openDatabase( + ':memory:', + options: OpenDatabaseOptions(singleInstance: false), + ); final db = MatrixSdkDatabase( 'unit_test.${c?.hashCode}', database: database, diff --git a/test/fake_matrix_api.dart b/test/fake_matrix_api.dart index 5e8001cb..0b19e5ec 100644 --- a/test/fake_matrix_api.dart +++ b/test/fake_matrix_api.dart @@ -1735,7 +1735,7 @@ class FakeMatrixApi extends BaseClient { } ] }, - '/client/v3/rooms/!726s6s6q:example.com/members': (var req) => { + '/client/v3/rooms/!726s6s6q%3Aexample.com/members': (var req) => { 'chunk': [ { 'content': { diff --git a/test/room_test.dart b/test/room_test.dart index d4a4da7d..104331c7 100644 --- a/test/room_test.dart +++ b/test/room_test.dart @@ -454,7 +454,7 @@ void main() { 'sender': '@test:example.com', 'redacts': '9', 'event_id': '10', - 'origin_server_ts': DateTime.now(), + 'origin_server_ts': DateTime.now().millisecondsSinceEpoch, }, stateKey: '', ),