Skip to content

Commit

Permalink
don't seed crdt db when creating to avoid sync issues on second sync
Browse files Browse the repository at this point in the history
  • Loading branch information
hahn-kev committed Nov 25, 2024
1 parent 373a5ec commit aab1366
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public async Task InitializeAsync()
if (Path.Exists(crdtProjectsFolder)) Directory.Delete(crdtProjectsFolder, true);
Directory.CreateDirectory(crdtProjectsFolder);
var crdtProject = await _services.ServiceProvider.GetRequiredService<ProjectsService>()
.CreateProject(new(_projectName, FwProjectId: FwDataApi.ProjectId, SeedNewProjectData: true));
.CreateProject(new(_projectName, FwProjectId: FwDataApi.ProjectId, SeedNewProjectData: false));
CrdtApi = (CrdtMiniLcmApi) await _services.ServiceProvider.OpenCrdtProject(crdtProject);
}

Expand Down
23 changes: 18 additions & 5 deletions backend/FwLite/FwLiteProjectSync.Tests/SyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public async Task DisposeAsync()
{
await _fixture.CrdtApi.DeleteEntry(entry.Id);
}

_fixture.DeleteSyncSnapshot();
}

public SyncTests(SyncFixture fixture)
Expand All @@ -84,7 +86,18 @@ public async Task FirstSyncJustDoesAnImport()
var fwdataEntries = await fwdataApi.GetEntries().ToArrayAsync();
crdtEntries.Should().BeEquivalentTo(fwdataEntries,
options => options.For(e => e.Components).Exclude(c => c.Id)
.For(e => e.ComplexForms).Exclude(c => c.Id));
.For(e => e.ComplexForms).Exclude(c => c.Id));
}

[Fact]
public async Task SecondSyncDoesNothing()
{
var crdtApi = _fixture.CrdtApi;
var fwdataApi = _fixture.FwDataApi;
await _syncService.Sync(crdtApi, fwdataApi);
var secondSync = await _syncService.SyncDryRun(crdtApi, fwdataApi);
secondSync.CrdtChanges.Should().Be(0, $"changes were {string.Join(", ", secondSync.CrdtDryRunRecords)}");
secondSync.FwdataChanges.Should().Be(0, $"changes were {string.Join(", ", secondSync.FwDataDryRunRecords)}");
}

[Fact]
Expand Down Expand Up @@ -273,15 +286,15 @@ await fwdataApi.CreateEntry(new Entry()
LexemeForm = { { "en", "Pear" } },
Senses =
[
new Sense() { Gloss = { { "en", "Pear" } }, SemanticDomains = [ semdom3 ] }
new Sense() { Gloss = { { "en", "Pear" } }, SemanticDomains = [semdom3] }
]
});
await crdtApi.CreateEntry(new Entry()
{
LexemeForm = { { "en", "Banana" } },
Senses =
[
new Sense() { Gloss = { { "en", "Banana" } }, SemanticDomains = [ semdom3 ] }
new Sense() { Gloss = { { "en", "Banana" } }, SemanticDomains = [semdom3] }
]
});
await _syncService.Sync(crdtApi, fwdataApi);
Expand Down Expand Up @@ -365,15 +378,15 @@ public async Task AddingASenseToAnEntryInEachProjectSyncsAcrossBoth()
await _syncService.Sync(crdtApi, fwdataApi);

await fwdataApi.CreateSense(_testEntry.Id, new Sense()
{
{
Gloss = { { "en", "Fruit" } },
Definition = { { "en", "a round fruit, red or yellow" } },
});
await crdtApi.CreateSense(_testEntry.Id, new Sense()
{
Gloss = { { "en", "Tree" } },
Definition = { { "en", "a tall, woody plant, which grows fruit" } },
});
});

await _syncService.Sync(crdtApi, fwdataApi);

Expand Down

0 comments on commit aab1366

Please sign in to comment.