Skip to content

Commit 5a7bb65

Browse files
committed
Unskip session tests on Windows
1 parent 2739bf3 commit 5a7bb65

File tree

3 files changed

+33
-19
lines changed

3 files changed

+33
-19
lines changed

sqlite3/lib/src/session.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ import 'sqlite3.dart';
1414
///
1515
/// {@category common}
1616
abstract interface class Session {
17+
/// Creates a new session on the given [CommonDatabase] and the optional
18+
/// [name] of the schema to track.
19+
///
20+
/// __Important__: While `package:sqlite3` uses native finalizers on both the
21+
/// database and the session object to ensure they're cleared automatically
22+
/// once they're no longer used in Dart, the order in which the objects are
23+
/// cleared matters. It is important that the session is closed is before the
24+
/// database, closing it afterwards may crash.
25+
///
26+
/// This ordering can't be guaranteed with native finalizers alone. For this
27+
/// reason, returned [Session]s should be [Session.delete]d explicitly as soon
28+
/// as they're no longer needed.
1729
factory Session(CommonDatabase database, {String name = 'main'}) {
1830
final asImpl = database as DatabaseImplementation;
1931
return SessionImplementation.createSession(asImpl, name);

sqlite3/test/common/session.dart

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,22 @@ void testSession(FutureOr<CommonSqlite3> Function() loadSqlite) {
2121
});
2222
tearDown(() => database.dispose());
2323

24-
test('enabled by default', () {
24+
Session createSession() {
2525
final session = Session(database);
26+
// Ensure we close the session before disposing the database. SQLite
27+
// mentions that session objects should be closed before the database, and
28+
// that closing them afterwards is UB.
29+
addTearDown(session.delete);
30+
return session;
31+
}
32+
33+
test('enabled by default', () {
34+
final session = createSession();
2635
expect(session.enabled, isTrue);
2736
});
2837

2938
test('isEmpty', () {
30-
final session = Session(database);
39+
final session = createSession();
3140
expect(session.isEmpty, isTrue);
3241
expect(session.isNotEmpty, isFalse);
3342

@@ -45,7 +54,7 @@ void testSession(FutureOr<CommonSqlite3> Function() loadSqlite) {
4554
});
4655

4756
test('attaching to some tables only', () {
48-
final session = Session(database);
57+
final session = createSession();
4958
expect(session.isEmpty, isTrue);
5059
session.attach('entries');
5160
database.execute('INSERT INTO other (content) VALUES (?);', [
@@ -56,7 +65,7 @@ void testSession(FutureOr<CommonSqlite3> Function() loadSqlite) {
5665
});
5766

5867
test('iterator', () {
59-
final session = Session(database)..attach();
68+
final session = createSession()..attach();
6069
database
6170
..execute('INSERT INTO entries (content) VALUES (?);', ['a'])
6271
..execute('UPDATE entries SET content = ?', ['b']);
@@ -89,7 +98,7 @@ void testSession(FutureOr<CommonSqlite3> Function() loadSqlite) {
8998
});
9099

91100
test('changeset invert', () {
92-
final session = Session(database)..attach();
101+
final session = createSession()..attach();
93102
database.execute('INSERT INTO entries (content) VALUES (?);', ['a']);
94103

95104
final changeset = session.changeset();
@@ -111,7 +120,7 @@ void testSession(FutureOr<CommonSqlite3> Function() loadSqlite) {
111120
});
112121

113122
test('apply changeset', () {
114-
final session = Session(database)..attach();
123+
final session = createSession()..attach();
115124
database.execute('INSERT INTO entries (content) VALUES (?);', ['a']);
116125
final changeset = session.changeset();
117126
session.delete();
@@ -126,7 +135,7 @@ void testSession(FutureOr<CommonSqlite3> Function() loadSqlite) {
126135
});
127136

128137
test('apply patchset', () {
129-
final session = Session(database)..attach();
138+
final session = createSession()..attach();
130139
database.execute('INSERT INTO entries (content) VALUES (?);', ['a']);
131140
final patchset = session.patchset();
132141
session.delete();
@@ -140,7 +149,7 @@ void testSession(FutureOr<CommonSqlite3> Function() loadSqlite) {
140149
});
141150

142151
test('diff', () {
143-
var session = Session(database);
152+
var session = createSession();
144153
database.execute('INSERT INTO entries (content) VALUES (?);', ['a']);
145154

146155
database
@@ -150,7 +159,7 @@ void testSession(FutureOr<CommonSqlite3> Function() loadSqlite) {
150159
)
151160
..execute('INSERT INTO another.entries (content) VALUES (?);', ['b']);
152161

153-
session = Session(database)..diff('another', 'entries');
162+
session = createSession()..diff('another', 'entries');
154163
final changeset = session.changeset();
155164
expect(changeset.toList(), [
156165
isOp(
Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
@Tags(['ffi'])
22
library;
33

4-
import 'dart:io';
5-
64
import 'package:sqlite3/sqlite3.dart';
75
import 'package:test/scaffolding.dart';
86

@@ -20,12 +18,7 @@ void main() {
2018
hasSharedCache: hasSharedCache,
2119
);
2220

23-
if (!Platform.isWindows) {
24-
// TODO: Something is wrong with session tests on Windows, but I couldn't
25-
// reproduce the issue in a VM yet.
26-
27-
group('session', () {
28-
testSession(() => sqlite3);
29-
}, skip: hasSession ? false : 'Missing session extension');
30-
}
21+
group('session', () {
22+
testSession(() => sqlite3);
23+
}, skip: hasSession ? false : 'Missing session extension');
3124
}

0 commit comments

Comments
 (0)