Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

realm compact #1005

Merged
merged 23 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions test/realm_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1470,11 +1470,14 @@ Future<void> main([List<String>? args]) async {
final credentials = Credentials.anonymous();
final user = await app.logIn(credentials);
List<int> key = List<int>.generate(encryptionKeySize, (i) => random.nextInt(256));
final configuration =
final config =
Configuration.flexibleSync(user, [Task.schema], encryptionKey: key, path: p.join(Configuration.defaultStoragePath, "${generateRandomString(8)}.realm"));

final compacted = await Realm.compact(configuration);
final compacted = await Realm.compact(config);
expect(compacted, true);

//test the realm can be opened. This also allows the compacted realm to be deleted after the test
blagoev marked this conversation as resolved.
Show resolved Hide resolved
final realm = getRealm(config);
blagoev marked this conversation as resolved.
Show resolved Hide resolved
});
}

Expand Down
11 changes: 9 additions & 2 deletions test/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -465,13 +465,20 @@ Future<void> tryDeleteRealm(String path) async {
return;
}

final dummy = File("");
const duration = Duration(milliseconds: 100);
for (var i = 0; i < 5; i++) {
try {
Realm.deleteRealm(path);
await File('$path.lock').delete();

//delete lock file
await File('$path.lock').delete().onError((error, stackTrace) => dummy);

//delete compaction space file
await File('$path.tmp_compaction_space').delete().onError((error, stackTrace) => dummy);
blagoev marked this conversation as resolved.
Show resolved Hide resolved

blagoev marked this conversation as resolved.
Show resolved Hide resolved
return;
} catch (e) {
const duration = Duration(milliseconds: 100);
print('Failed to delete realm at path $path. Trying again in ${duration.inMilliseconds}ms');
await Future<void>.delayed(duration);
}
Expand Down