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