compareLogStores function

Future<List<LogStoreMismatch>> compareLogStores(
  1. LogStore store, {
  2. required LogStore reference,
  3. required int seed,
  4. int rounds = 12,
  5. bool compareIds = true,
})

Checks store against the LogStore contract by comparing it with reference (an InMemoryLogStore with the same limit, whose queryInMemory and LogCondition.matches define the semantics) over rounds rounds of the LogStoreScenario for seed. Returns the mismatches; an empty list means the store behaved like the reference for this seed. A package's contract test runs a few seeds and asserts the list is empty:

for (final seed in [1, 2, 3]) {
  test('seed $seed matches the reference', () async {
    final mismatches = await compareLogStores(MyStore(), reference: InMemoryLogStore(limit: 40), seed: seed);
    expect(mismatches, isEmpty);
  });
}

Neither store is closed: the caller owns both.

Implementation

Future<List<LogStoreMismatch>> compareLogStores(
  LogStore store, {
  required LogStore reference,
  required int seed,
  int rounds = 12,
  bool compareIds = true,
}) async {
  final check = LogStoreContractCheck(
    store: store,
    reference: reference,
    scenario: LogStoreScenario(seed),
    compareIds: compareIds,
  );
  for (var i = 0; i < rounds; i++) {
    await check.round();
  }
  await check.finish();
  return check.mismatches;
}