Skip to content

Commit d798dd6

Browse files
committed
libsql-sqlite3: Test case for syncing while reading
We need to make sure we test a case where page cache is non-empty.
1 parent 49b5d26 commit d798dd6

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

libsql-sqlite3/src/test_walapi.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,42 @@ void test_sync_by_parts() {
119119
cmp_data(db_primary, db_backup);
120120
}
121121

122+
// This test case writes to a local database, syncs it to remote, and then verifies the remote.
123+
// The test then writes some more to local database, syncs it again, and verifies the remote again.
124+
void test_sync_while_reading() {
125+
sqlite3 *db_primary, *db_backup;
126+
unsigned int max_frame;
127+
open_db("primary_test_sync_while_reading.db", &db_primary);
128+
ensure(sqlite3_exec(db_primary, "CREATE TABLE t (x)", 0, 0, 0) == SQLITE_OK, "failed to insert data\n");
129+
ensure(sqlite3_exec(db_primary, "INSERT INTO t VALUES (randomblob(4 * 1024))", 0, 0, 0) == SQLITE_OK, "failed to insert data\n");
130+
ensure(sqlite3_exec(db_primary, "INSERT INTO t VALUES (randomblob(1 * 1024))", 0, 0, 0) == SQLITE_OK, "failed to insert data\n");
131+
ensure(sqlite3_exec(db_primary, "INSERT INTO t VALUES (randomblob(1 * 1024))", 0, 0, 0) == SQLITE_OK, "failed to insert data\n");
132+
133+
open_db("backup_test_sync_while_reading.db", &db_backup);
134+
ensure(libsql_wal_frame_count(db_backup, &max_frame) == SQLITE_OK, "failed to get frames count: %s\n", sqlite3_errmsg(db_backup));
135+
assert(max_frame == 0);
136+
137+
eprintf("start full sync\n");
138+
sync_db(db_primary, db_backup);
139+
cmp_data(db_primary, db_backup);
140+
141+
ensure(sqlite3_exec(db_primary, "INSERT INTO t VALUES (randomblob(4 * 1024))", 0, 0, 0) == SQLITE_OK, "failed to insert data\n");
142+
ensure(sqlite3_exec(db_primary, "INSERT INTO t VALUES (randomblob(1 * 1024))", 0, 0, 0) == SQLITE_OK, "failed to insert data\n");
143+
ensure(sqlite3_exec(db_primary, "INSERT INTO t VALUES (randomblob(1 * 1024))", 0, 0, 0) == SQLITE_OK, "failed to insert data\n");
144+
sync_db(db_primary, db_backup);
145+
cmp_data(db_primary, db_backup);
146+
}
147+
122148
int main(int argc, char *argv[])
123149
{
124150
test_huge_payload();
125151
printf("============= OK test_huge_payload\n");
126152

127153
test_sync_by_parts();
128154
printf("============= OK test_sync_by_parts\n");
155+
156+
test_sync_while_reading();
157+
printf("============= OK test_sync_while_reading\n");
158+
129159
return 0;
130160
}

0 commit comments

Comments
 (0)