Skip to content

Commit a10e59f

Browse files
committed
Include name of navigator lock on abort
1 parent 0cd272f commit a10e59f

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

packages/sqlite_async/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.14.3 (unreleased)
2+
3+
- Include identifier of mutexes when a navigator lock attempt is aborted.
4+
15
## 0.14.2
26

37
- Support versions `0.8.x` of `package:sqlite3_web`.

packages/sqlite_async/lib/src/web/web_mutex.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ class WebMutexImpl implements Mutex {
7272
if (abortTrigger != null) {
7373
abortTrigger.whenComplete(() {
7474
if (!gotLock.isCompleted) {
75-
gotLock.completeError(AbortException('getWebLock'));
75+
gotLock
76+
.completeError(AbortException('getWebLock($resolvedIdentifier)'));
7677
controller.abort('aborted in Dart'.toJS);
7778
}
7879
});

packages/sqlite_async/test/web/web_mutex_test.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
@TestOn('browser')
22
library;
33

4+
import 'dart:async';
5+
6+
import 'package:sqlite_async/sqlite_async.dart';
47
import 'package:sqlite_async/src/web/web_mutex.dart';
58
import 'package:test/test.dart';
9+
import 'package:web/web.dart';
610

711
import '../utils/test_utils_impl.dart';
812

@@ -28,5 +32,30 @@ void main() {
2832
// It should be correctly ordered as if it was the same mutex
2933
expect(results, equals([1, 2]));
3034
});
35+
36+
test('can abort acquiring navigator locks', () async {
37+
final lockName = window.crypto.randomUUID();
38+
final m1 = WebMutexImpl(identifier: lockName);
39+
final m2 = WebMutexImpl(identifier: lockName);
40+
41+
final hasM1 = Completer();
42+
final releaseM1 = Completer();
43+
m1.lock(() {
44+
hasM1.complete();
45+
return releaseM1.future;
46+
});
47+
48+
await hasM1.future;
49+
expect(
50+
m2.lock(
51+
expectAsync0(() async {}, count: 0),
52+
abortTrigger: Future.delayed(Duration.zero),
53+
),
54+
throwsA(
55+
isA<AbortException>()
56+
.having((e) => e.toString(), 'toString()', contains(lockName)),
57+
),
58+
);
59+
});
3160
});
3261
}

0 commit comments

Comments
 (0)