finish method

Future<void> finish()

Compares the change streams once the stores have delivered them.

Implementation

Future<void> finish() async {
  // Two turns: LogStoreBase emits after the write completes, the broadcast stream delivers on the next.
  await Future<void>.delayed(Duration.zero);
  await Future<void>.delayed(Duration.zero);
  _compare(
    'changes',
    expected: _referenceChanges.map((c) => c.runtimeType).toList(),
    actual: _storeChanges.map((c) => c.runtimeType).toList(),
  );
  for (final (index, expected) in _referenceChanges.indexed) {
    if (index >= _storeChanges.length) break;
    final actual = _storeChanges[index];
    switch (expected) {
      case LogEntriesAdded(:final entries):
        if (actual is LogEntriesAdded) {
          _compare('changes[$index] LogEntriesAdded', expected: _stored(entries), actual: _stored(actual.entries));
        }
      case LogEntriesRemovedById(:final ids):
        if (actual is LogEntriesRemovedById) {
          _compare(
            'changes[$index] LogEntriesRemovedById',
            expected: compareIds ? ids : ids.length,
            actual: compareIds ? actual.ids : actual.ids.length,
          );
        }
      case LogEntriesRemovedBefore(:final time):
        if (actual is LogEntriesRemovedBefore) {
          _compare('changes[$index] LogEntriesRemovedBefore', expected: time, actual: actual.time);
        }
      case AllLogEntriesRemoved() || LogStoreInvalidated():
        break;
    }
  }
}