replicateBenchmarkTest function
void
replicateBenchmarkTest({
- required FoodbTestContext source,
- required FoodbTestContext target,
- required int batchSize,
- required int thousandDoc,
- String? customSourceDb,
- bool resetSource = false,
Implementation
void replicateBenchmarkTest({
required FoodbTestContext source,
required FoodbTestContext target,
required int batchSize,
required int thousandDoc,
String? customSourceDb,
bool resetSource = false,
}) {
var fromType = source.runtimeType.toString();
var toType = target.runtimeType.toString();
test('$fromType to $toType: ${thousandDoc}k-benchmark', () async {
var from;
if (customSourceDb != null) {
from = await source.db(customSourceDb, persist: true, prefix: '');
} else {
from = await source.db('replication-benchmark-source-${thousandDoc}k',
persist: true);
}
final to = await target.db('replication-benchmark-target-${thousandDoc}k');
var fromInfo = await from.info();
if (fromInfo.docCount == 0 || resetSource) {
await from.destroy();
await from.initDb();
await generateSourceDb(
db: from,
docCount: thousandDoc * 1000,
);
}
var totalStopWatch = Stopwatch()..start();
var fn = expectAsync0(() async {
totalStopWatch.stop();
print('done: ${totalStopWatch.elapsed.inSeconds}');
print(
'perDoc: ${totalStopWatch.elapsed.inMilliseconds / (thousandDoc * 1000)}');
final fromAll = await from.allDocs(GetViewRequest(), (json) => json);
final toAll = await from.allDocs(GetViewRequest(), (json) => json);
expect(fromAll.totalRows, equals(toAll.totalRows));
});
replicate(
from,
to,
maxBatchSize: batchSize,
createTarget: true,
onError: (e, s) {
throw e ?? Exception();
},
onComplete: fn,
);
}, timeout: Timeout(Duration(minutes: 30)));
}