-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* introduce performance regression tests * ensure the harmony table names are consistent now that we have a hardcoded sql query * add test to ensure changes are round tripped through the db properly * Fix bug where changes outside the model were saved in snapshots, covered with `ChangesToSnapshotsAreNotSaved`. Fixing that uncovered tests that depend on snapshots being tracked between test phases. Also fixed tests which were over-specifying the expected time when there was a mismatch in time offset that was acceptable. * add HybridDateTimeTests.cs * Define interface to describe Changes return value, should help APIs implement the matching return type without restricting the collection type. Split `GetChanges` helper to `GetMissingCommits` which returns an IAsyncEnumerable, this allows the server to use less memory when responding to requests with a large number of commits * introduce test to ensure that changes can still be written after an application restart * fix bug where you couldn't submit updates to an existing entity after creating a new data model instance.
- Loading branch information
Showing
20 changed files
with
592 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
namespace SIL.Harmony.Core; | ||
|
||
public record SyncState(Dictionary<Guid, long> ClientHeads); | ||
|
||
public record ChangesResult<TCommit>(TCommit[] MissingFromClient, SyncState ServerSyncState) where TCommit : CommitBase | ||
public interface IChangesResult | ||
{ | ||
IEnumerable<CommitBase> MissingFromClient { get; } | ||
SyncState ServerSyncState { get; } | ||
} | ||
public record ChangesResult<TCommit>(TCommit[] MissingFromClient, SyncState ServerSyncState): IChangesResult where TCommit : CommitBase | ||
{ | ||
IEnumerable<CommitBase> IChangesResult.MissingFromClient => MissingFromClient; | ||
public static ChangesResult<TCommit> Empty => new([], new SyncState([])); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using SIL.Harmony.Core; | ||
|
||
namespace SIL.Harmony.Tests.Core; | ||
|
||
public class HybridDateTimeTests | ||
{ | ||
[Fact] | ||
public void Equals_TrueWhenTheSame() | ||
{ | ||
var dateTime = new HybridDateTime(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), 0); | ||
var otherDateTime = new HybridDateTime(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), 0); | ||
|
||
(dateTime == otherDateTime).Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void Equals_FalseWhenDifferentDateTime() | ||
{ | ||
var dateTime = new HybridDateTime(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), 0); | ||
var otherDateTime = new HybridDateTime(new DateTimeOffset(2001, 1, 1, 0, 0, 0, TimeSpan.Zero), 0); | ||
|
||
(dateTime != otherDateTime).Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void Equals_FalseWhenDifferentCounter() | ||
{ | ||
var dateTime = new HybridDateTime(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), 0); | ||
var otherDateTime = new HybridDateTime(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), 1); | ||
|
||
dateTime.Should().NotBe(otherDateTime); | ||
} | ||
|
||
[Fact] | ||
public void Constructor_ThrowsArgumentOutOfRangeExceptionWhenCounterIsNegative() | ||
{ | ||
Action action = () => new HybridDateTime(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), -1); | ||
action.Should().Throw<ArgumentOutOfRangeException>(); | ||
} | ||
|
||
[Fact] | ||
public void CompareTo_ReturnsOneWhenOtherIsNull() | ||
{ | ||
var dateTime = new HybridDateTime(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), 0); | ||
dateTime.CompareTo(null).Should().Be(1); | ||
} | ||
|
||
[Fact] | ||
public void CompareTo_ReturnsNegativeOneWhenThisIsLessThanOther() | ||
{ | ||
var dateTime = new HybridDateTime(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), 0); | ||
var otherDateTime = new HybridDateTime(new DateTimeOffset(2000, 1, 2, 0, 0, 0, TimeSpan.Zero), 0); | ||
|
||
var result = dateTime.CompareTo(otherDateTime); | ||
result.Should().BeLessThan(0); | ||
} | ||
|
||
[Fact] | ||
public void CompareTo_ReturnsZeroWhenThisIsEqualToOther() | ||
{ | ||
var dateTime = new HybridDateTime(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), 0); | ||
var otherDateTime = new HybridDateTime(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), 0); | ||
|
||
var result = dateTime.CompareTo(otherDateTime); | ||
result.Should().Be(0); | ||
} | ||
|
||
[Fact] | ||
public void CompareTo_ReturnsOneWhenThisIsGreaterThanOther() | ||
{ | ||
var dateTime = new HybridDateTime(new DateTimeOffset(2000, 1, 2, 0, 0, 0, TimeSpan.Zero), 0); | ||
var otherDateTime = new HybridDateTime(new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero), 0); | ||
|
||
var result = dateTime.CompareTo(otherDateTime); | ||
result.Should().Be(1); | ||
} | ||
} |
Oops, something went wrong.