Skip to content

Commit 588d92f

Browse files
fix tests
1 parent 82b83c1 commit 588d92f

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

packages/sqlite_async/lib/src/native/native_isolate_mutex.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:sqlite_async/src/common/mutex.dart';
77
import 'package:sqlite_async/src/common/port_channel.dart';
88

99
abstract class MutexImpl implements Mutex {
10-
factory MutexImpl() {
10+
factory MutexImpl({String? identifier}) {
1111
return SimpleMutex();
1212
}
1313
}
@@ -19,12 +19,13 @@ class SimpleMutex implements MutexImpl {
1919
// Adapted from https://github.com/tekartik/synchronized.dart/blob/master/synchronized/lib/src/basic_lock.dart
2020

2121
Future<dynamic>? last;
22+
String? identifier;
2223

2324
// Hack to make sure the Mutex is not copied to another isolate.
2425
// ignore: unused_field
2526
final Finalizer _f = Finalizer((_) {});
2627

27-
SimpleMutex();
28+
SimpleMutex({this.identifier});
2829

2930
bool get locked => last != null;
3031

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ class MutexImpl implements Mutex {
5858
Future.delayed(timeout, () {
5959
isTimedOut = true;
6060
if (lockObtained == false) {
61-
completer.completeError(LockError('Timeout reached'));
61+
completer.completeError(
62+
TimeoutException('Failed to acquire lock', timeout));
6263
}
6364
});
6465
}
@@ -109,7 +110,8 @@ class MutexImpl implements Mutex {
109110
if (lockAcquired == true) {
110111
return;
111112
}
112-
gotLock.completeError(LockError('Timeout reached'));
113+
gotLock
114+
.completeError(TimeoutException('Failed to acquire lock', timeout));
113115
controller.abort('Timeout'.toJS);
114116
});
115117
}

packages/sqlite_async/test/mutex_test.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dart:async';
12
import 'dart:math';
23

34
import 'package:sqlite_async/sqlite_async.dart';
@@ -41,7 +42,9 @@ void main() {
4142
m.lock(() async {
4243
print('This should not get executed');
4344
}, timeout: Duration(milliseconds: 200)),
44-
throwsA((e) => e is LockError && e.message.contains('Timeout')));
45+
throwsA((e) =>
46+
e is TimeoutException &&
47+
e.message!.contains('Failed to acquire lock')));
4548
});
4649

4750
test('In-time timeout should function normally', () async {

0 commit comments

Comments
 (0)