Skip to content

Test coverage: DataModel.AddManyChanges bulk write and chunking #98

Description

@hahn-kev-bot

Follow-up from the test-suite review (batches merged as #92#96).

Gap

DataModel.AddManyChanges is a public bulk-write entry point with its own chunking (changesPerCommitMax, one commit per chunk) and empty-input early return (if (commits is []) return). No test calls it — the chunk-splitting math and per-chunk commit flow are entirely unverified.

public async Task AddManyChanges(Guid clientId,
IEnumerable<IChange> changes,
Func<CommitMetadata?> commitMetadata,
int changesPerCommitMax = 100)
{
await using var repo = await _crdtRepositoryFactory.CreateRepository();
var commits = changes
.Chunk(changesPerCommitMax)
.Select(chunk => NewCommit(clientId, commitMetadata(), chunk))
.ToArray();
if (commits is []) return;
using var locked = await repo.Lock();
repo.ClearChangeTracker();
await using var transaction = await repo.BeginTransactionAsync();
var updatedCommits = await repo.AddCommits(commits);
await UpdateSnapshots(repo, updatedCommits);
await ValidateCommits(repo);
await transaction.CommitAsync();
}

Suggested tests

  • AddManyChanges_SplitsChangesIntoCommitsOfMaxSize
  • AddManyChanges_WithNoChangesDoesNothing

Why it matters

It is a distinct write path with its own transaction/lock/validate flow; a bug in the chunking could silently mis-group changes into the wrong commits.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions