@@ -64,6 +64,39 @@ void main() {
6464 }
6565 });
6666
67+ test ('Concurrency 2' , () async {
68+ final db1 =
69+ SqliteDatabase .withFactory (testFactory (path: path), maxReaders: 3 );
70+
71+ final db2 =
72+ SqliteDatabase .withFactory (testFactory (path: path), maxReaders: 3 );
73+ await db1.initialize ();
74+ await createTables (db1);
75+ await db2.initialize ();
76+ print ("${DateTime .now ()} start" );
77+
78+ var futures1 = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ].map ((i) {
79+ return db1.execute (
80+ "INSERT OR REPLACE INTO test_data(id, description) SELECT ? as i, test_sleep(?) || ' ' || test_connection_name() || ' 1 ' || datetime() as connection RETURNING *" ,
81+ [
82+ i,
83+ 5 + Random ().nextInt (20 )
84+ ]).then ((value) => print ("${DateTime .now ()} $value " ));
85+ }).toList ();
86+
87+ var futures2 = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ].map ((i) {
88+ return db2.execute (
89+ "INSERT OR REPLACE INTO test_data(id, description) SELECT ? as i, test_sleep(?) || ' ' || test_connection_name() || ' 2 ' || datetime() as connection RETURNING *" ,
90+ [
91+ i,
92+ 5 + Random ().nextInt (20 )
93+ ]).then ((value) => print ("${DateTime .now ()} $value " ));
94+ }).toList ();
95+ await Future .wait (futures1);
96+ await Future .wait (futures2);
97+ print ("${DateTime .now ()} done" );
98+ });
99+
67100 test ('read-only transactions' , () async {
68101 final db = await setupDatabase (path: path);
69102 await createTables (db);
0 commit comments