Skip to content

Commit 8383d63

Browse files
committed
Add failing test.
1 parent 1c3f03b commit 8383d63

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

packages/service-core-tests/src/tests/register-data-storage-tests.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,4 +1878,54 @@ bucket_definitions:
18781878
}
18791879
});
18801880
});
1881+
1882+
test('op_id initialization edge case', async () => {
1883+
// Test syncing a batch of data that is small in count,
1884+
// but large enough in size to be split over multiple returned chunks.
1885+
// Similar to the above test, but splits over 1MB chunks.
1886+
const sync_rules = test_utils.testRules(
1887+
`
1888+
bucket_definitions:
1889+
global:
1890+
data:
1891+
- SELECT id FROM test
1892+
- SELECT id FROM test_ignore WHERE false
1893+
`
1894+
);
1895+
await using factory = await generateStorageFactory();
1896+
const bucketStorage = factory.getInstance(sync_rules);
1897+
1898+
const sourceTable = test_utils.makeTestTable('test', ['id']);
1899+
const sourceTableIgnore = test_utils.makeTestTable('test_ignore', ['id']);
1900+
1901+
const result1 = await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
1902+
// This saves a record to current_data, but not bucket_data.
1903+
// This causes a checkpoint to be created without increasing the op_id sequence.
1904+
await batch.save({
1905+
sourceTable: sourceTableIgnore,
1906+
tag: storage.SaveOperationTag.INSERT,
1907+
after: {
1908+
id: 'test1'
1909+
},
1910+
afterReplicaId: test_utils.rid('test1')
1911+
});
1912+
});
1913+
1914+
const checkpoint1 = result1!.flushed_op;
1915+
1916+
const result2 = await bucketStorage.startBatch(test_utils.BATCH_OPTIONS, async (batch) => {
1917+
await batch.save({
1918+
sourceTable: sourceTable,
1919+
tag: storage.SaveOperationTag.INSERT,
1920+
after: {
1921+
id: 'test2'
1922+
},
1923+
afterReplicaId: test_utils.rid('test2')
1924+
});
1925+
});
1926+
1927+
const checkpoint2 = result2!.flushed_op;
1928+
// we expect 0n and 1n, or 1n and 2n.
1929+
expect(checkpoint2).toBeGreaterThan(checkpoint1);
1930+
});
18811931
}

0 commit comments

Comments
 (0)