@@ -71,6 +71,37 @@ void main() {
7171 }
7272 });
7373
74+ test ('Concurrency 2' , () async {
75+ final db1 = await testUtils.setupDatabase (path: path, maxReaders: 3 );
76+ final db2 = await testUtils.setupDatabase (path: path, maxReaders: 3 );
77+
78+ await db1.initialize ();
79+ await createTables (db1);
80+ await db2.initialize ();
81+ print ("${DateTime .now ()} start" );
82+
83+ var futures1 = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ].map ((i) {
84+ return db1.execute (
85+ "INSERT OR REPLACE INTO test_data(id, description) SELECT ? as i, test_sleep(?) || ' ' || test_connection_name() || ' 1 ' || datetime() as connection RETURNING *" ,
86+ [
87+ i,
88+ 5 + Random ().nextInt (20 )
89+ ]).then ((value) => print ("${DateTime .now ()} $value " ));
90+ }).toList ();
91+
92+ var futures2 = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ].map ((i) {
93+ return db2.execute (
94+ "INSERT OR REPLACE INTO test_data(id, description) SELECT ? as i, test_sleep(?) || ' ' || test_connection_name() || ' 2 ' || datetime() as connection RETURNING *" ,
95+ [
96+ i,
97+ 5 + Random ().nextInt (20 )
98+ ]).then ((value) => print ("${DateTime .now ()} $value " ));
99+ }).toList ();
100+ await Future .wait (futures1);
101+ await Future .wait (futures2);
102+ print ("${DateTime .now ()} done" );
103+ });
104+
74105 test ('with all connections' , () async {
75106 final db = SqliteDatabase .withFactory (
76107 await testUtils.testFactory (path: path),
@@ -129,37 +160,6 @@ void main() {
129160 await readsCalledWhileWithAllConnsRunning;
130161 });
131162
132- test ('Concurren 2' , () async {
133- final db1 = await testUtils.setupDatabase (path: path, maxReaders: 3 );
134- final db2 = await testUtils.setupDatabase (path: path, maxReaders: 3 );
135-
136- await db1.initialize ();
137- await createTables (db1);
138- await db2.initialize ();
139- print ("${DateTime .now ()} start" );
140-
141- var futures1 = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ].map ((i) {
142- return db1.execute (
143- "INSERT OR REPLACE INTO test_data(id, description) SELECT ? as i, test_sleep(?) || ' ' || test_connection_name() || ' 1 ' || datetime() as connection RETURNING *" ,
144- [
145- i,
146- 5 + Random ().nextInt (20 )
147- ]).then ((value) => print ("${DateTime .now ()} $value " ));
148- }).toList ();
149-
150- var futures2 = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ].map ((i) {
151- return db2.execute (
152- "INSERT OR REPLACE INTO test_data(id, description) SELECT ? as i, test_sleep(?) || ' ' || test_connection_name() || ' 2 ' || datetime() as connection RETURNING *" ,
153- [
154- i,
155- 5 + Random ().nextInt (20 )
156- ]).then ((value) => print ("${DateTime .now ()} $value " ));
157- }).toList ();
158- await Future .wait (futures1);
159- await Future .wait (futures2);
160- print ("${DateTime .now ()} done" );
161- });
162-
163163 test ('read-only transactions' , () async {
164164 final db = await testUtils.setupDatabase (path: path);
165165 await createTables (db);
0 commit comments