Settings › Archive reads archive.json without the settings lease each time it is shown and after a waited edit. On a slow share such a read could return the file as it was before a template, proxy or thumbnail edit that was being written, then put the old value back on the row and in this PC's defaults while the archive kept the edit. ArchiveReadGate now drops a read that overlapped an edit being written; the rows are read again at once, or when the last edit being written ends. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
83 lines
3.2 KiB
C#
83 lines
3.2 KiB
C#
using Titano.App.Settings;
|
||
using Titano.Testing;
|
||
|
||
namespace Titano.App.Tests.Settings;
|
||
|
||
/// <summary>
|
||
/// Settings › Archive never shows a read of the archive's settings that overlapped an edit being written: on a slow share
|
||
/// that read can hold archive.json as it was before the edit, and would undo the edit on the rows and in this PC's
|
||
/// defaults while the archive keeps it.
|
||
/// </summary>
|
||
public sealed class ArchiveReadGateTests
|
||
{
|
||
[Test]
|
||
public void AReadWithNoEditMeanwhileIsShown()
|
||
{
|
||
var gate = new ArchiveReadGate();
|
||
Assert.True(gate.IsCurrent(gate.BeginRead(), out var again));
|
||
Assert.False(again);
|
||
|
||
// An edit written and ended before the read began is in the file it reads.
|
||
gate.BeginWrite();
|
||
Assert.False(gate.EndWrite(), "no read overlapped it");
|
||
Assert.True(gate.IsCurrent(gate.BeginRead(), out again));
|
||
Assert.False(again);
|
||
}
|
||
|
||
[Test]
|
||
public void AReadThatAnEditOverlapsIsReadAgainWhenTheEditIsWritten()
|
||
{
|
||
// Settings is shown and reads archive.json; the user commits a template before the read answers.
|
||
var gate = new ArchiveReadGate();
|
||
var read = gate.BeginRead();
|
||
gate.BeginWrite();
|
||
Assert.False(gate.IsCurrent(read, out var again), "the read may hold the file before the edit");
|
||
Assert.False(again, "the edit is still being written: its end reads again");
|
||
Assert.True(gate.EndWrite(), "the edit's end reads the rows again");
|
||
|
||
// That read is shown, and asks nothing more of later edits.
|
||
Assert.True(gate.IsCurrent(gate.BeginRead(), out again));
|
||
gate.BeginWrite();
|
||
Assert.False(gate.EndWrite());
|
||
}
|
||
|
||
[Test]
|
||
public void AReadOverlappingAnEditAlreadyWrittenIsReadAgainAtOnce()
|
||
{
|
||
// The edit began and ended while the read was out.
|
||
var gate = new ArchiveReadGate();
|
||
var read = gate.BeginRead();
|
||
gate.BeginWrite();
|
||
Assert.False(gate.EndWrite(), "the read was not dropped yet");
|
||
Assert.False(gate.IsCurrent(read, out var again));
|
||
Assert.True(again, "nothing else reads again: the read does");
|
||
|
||
// A read that began while an edit was being written, which ended before the read answered.
|
||
gate.BeginWrite();
|
||
read = gate.BeginRead();
|
||
Assert.False(gate.EndWrite());
|
||
Assert.False(gate.IsCurrent(read, out again));
|
||
Assert.True(again);
|
||
Assert.True(gate.IsCurrent(gate.BeginRead(), out again));
|
||
}
|
||
|
||
[Test]
|
||
public void OnlyTheLastOfSeveralEditsReadsAgain()
|
||
{
|
||
// A proxy size and a thumbnail size picked one after the other, both overlapping a read.
|
||
var gate = new ArchiveReadGate();
|
||
var read = gate.BeginRead();
|
||
gate.BeginWrite();
|
||
gate.BeginWrite();
|
||
Assert.False(gate.IsCurrent(read, out var again));
|
||
Assert.False(again);
|
||
Assert.False(gate.EndWrite(), "another edit is still being written");
|
||
// A read begun meanwhile is dropped too, and left to the last edit.
|
||
read = gate.BeginRead();
|
||
Assert.False(gate.IsCurrent(read, out again));
|
||
Assert.False(again);
|
||
Assert.True(gate.EndWrite());
|
||
Assert.Throws<InvalidOperationException>(() => gate.EndWrite());
|
||
}
|
||
}
|