@@ -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 (
0 commit comments