refactor(uploader): drop members only tests used
Tests write serialized queue and watch-memory bytes directly; the app persists through its coalescing writer. Single-instance hand-over no longer returns an unused flag. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
8 files changed
+8
-24
No files matched your search
@@ -64,7 +64,7 @@ public partial class App : Application
|
|||||||
_instance = SingleInstance.TryAcquire();
|
_instance = SingleInstance.TryAcquire();
|
||||||
if (_instance is null)
|
if (_instance is null)
|
||||||
{
|
{
|
||||||
SingleInstance.TrySend([.. command.Paths.Select(Absolute).OfType<string>()]);
|
SingleInstance.HandOver([.. command.Paths.Select(Absolute).OfType<string>()]);
|
||||||
Log.Info("app", "Another uploader runs in this session; arguments handed over");
|
Log.Info("app", "Another uploader runs in this session; arguments handed over");
|
||||||
Shutdown();
|
Shutdown();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public sealed class SingleInstance : IDisposable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Sends <paramref name="args"/> (absolute paths; empty = just show the window) to the running instance.</summary>
|
/// <summary>Sends <paramref name="args"/> (absolute paths; empty = just show the window) to the running instance.</summary>
|
||||||
public static bool TrySend(IReadOnlyList<string> args)
|
public static void HandOver(IReadOnlyList<string> args)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -41,12 +41,10 @@ public sealed class SingleInstance : IDisposable
|
|||||||
pipe.Connect(3000);
|
pipe.Connect(3000);
|
||||||
pipe.Write(Encode(args));
|
pipe.Write(Encode(args));
|
||||||
pipe.Flush();
|
pipe.Flush();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
catch (Exception ex) when (ex is IOException or TimeoutException or UnauthorizedAccessException)
|
catch (Exception ex) when (ex is IOException or TimeoutException or UnauthorizedAccessException)
|
||||||
{
|
{
|
||||||
Log.Warning("instance", "Could not reach the running uploader", ex);
|
Log.Warning("instance", "Could not reach the running uploader", ex);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,7 @@ using Titano.Protocol;
|
|||||||
namespace Titano.Uploader.Server;
|
namespace Titano.Uploader.Server;
|
||||||
|
|
||||||
/// <summary>A Titano Server announced on the LAN.</summary>
|
/// <summary>A Titano Server announced on the LAN.</summary>
|
||||||
public sealed record DiscoveredServer(string Name, string Address)
|
public sealed record DiscoveredServer(string Name, string Address);
|
||||||
{
|
|
||||||
public override string ToString() => Name + " · " + Address;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Listens for the server's UDP beacon (<see cref="DiscoveryBeacon.Port"/>) while the connect form is open and reports
|
/// Listens for the server's UDP beacon (<see cref="DiscoveryBeacon.Port"/>) while the connect form is open and reports
|
||||||
@@ -31,17 +28,15 @@ public sealed class DiscoveryListener : IDisposable
|
|||||||
_ = Task.Run(() => ListenAsync(context, _cts.Token));
|
_ = Task.Run(() => ListenAsync(context, _cts.Token));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Stop()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_cts?.Cancel();
|
_cts?.Cancel();
|
||||||
_cts?.Dispose();
|
_cts?.Dispose();
|
||||||
_cts = null;
|
_cts = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose() => Stop();
|
|
||||||
|
|
||||||
/// <summary>The address the client should use for <paramref name="beacon"/> sent from <paramref name="sender"/>.</summary>
|
/// <summary>The address the client should use for <paramref name="beacon"/> sent from <paramref name="sender"/>.</summary>
|
||||||
public static string AddressOf(DiscoveryBeacon beacon, IPAddress sender)
|
private static string AddressOf(DiscoveryBeacon beacon, IPAddress sender)
|
||||||
{
|
{
|
||||||
var host = sender.AddressFamily == AddressFamily.InterNetworkV6 ? "[" + sender + "]" : sender.ToString();
|
var host = sender.AddressFamily == AddressFamily.InterNetworkV6 ? "[" + sender + "]" : sender.ToString();
|
||||||
return beacon.HttpsPort > 0 ? $"https://{host}:{beacon.HttpsPort}" : $"http://{host}:{beacon.HttpPort}";
|
return beacon.HttpsPort > 0 ? $"https://{host}:{beacon.HttpsPort}" : $"http://{host}:{beacon.HttpPort}";
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ using System.IO;
|
|||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Titano.Core.Diagnostics;
|
using Titano.Core.Diagnostics;
|
||||||
using Titano.Core.IO;
|
|
||||||
|
|
||||||
namespace Titano.Uploader.Uploads;
|
namespace Titano.Uploader.Uploads;
|
||||||
|
|
||||||
@@ -73,9 +72,6 @@ public static class QueueStore
|
|||||||
file.Paused);
|
file.Paused);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Commits serialized bytes with temp → fsync → rename.</summary>
|
|
||||||
public static void Write(string path, byte[] content) => AtomicFile.WriteAllBytes(path, content);
|
|
||||||
|
|
||||||
internal sealed class QueueFile
|
internal sealed class QueueFile
|
||||||
{
|
{
|
||||||
public int Version { get; set; }
|
public int Version { get; set; }
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ using System.IO;
|
|||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Titano.Core.Diagnostics;
|
using Titano.Core.Diagnostics;
|
||||||
using Titano.Core.IO;
|
|
||||||
using Titano.Uploader.Sources;
|
using Titano.Uploader.Sources;
|
||||||
|
|
||||||
namespace Titano.Uploader.Watching;
|
namespace Titano.Uploader.Watching;
|
||||||
@@ -106,8 +105,6 @@ public sealed class ProcessedFileMemory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Save(string path) => AtomicFile.WriteAllBytes(path, Serialize());
|
|
||||||
|
|
||||||
/// <summary>Loads <paramref name="path"/>; a missing or corrupt file gives an empty memory.</summary>
|
/// <summary>Loads <paramref name="path"/>; a missing or corrupt file gives an empty memory.</summary>
|
||||||
public static ProcessedFileMemory Load(string path)
|
public static ProcessedFileMemory Load(string path)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -44,6 +44,4 @@ public sealed class StableFileTracker
|
|||||||
_seen[o.Path] = (o.Size, o.ModifiedUtc, count);
|
_seen[o.Path] = (o.Size, o.ModifiedUtc, count);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Clear() => _seen.Clear();
|
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ public sealed class ProcessedFileMemoryTests(TestContext context)
|
|||||||
memory.SetSession(root, new SessionContinuation("1a2b3c4d-20260928-180000", new DateTime(2026, 9, 28, 18, 40, 0)));
|
memory.SetSession(root, new SessionContinuation("1a2b3c4d-20260928-180000", new DateTime(2026, 9, 28, 18, 40, 0)));
|
||||||
|
|
||||||
var path = Path.Combine(dir, "uploader-watch.json");
|
var path = Path.Combine(dir, "uploader-watch.json");
|
||||||
memory.Save(path);
|
File.WriteAllBytes(path, memory.Serialize());
|
||||||
Assert.False(memory.IsDirty);
|
Assert.False(memory.IsDirty);
|
||||||
var restored = ProcessedFileMemory.Load(path);
|
var restored = ProcessedFileMemory.Load(path);
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public sealed class UploadQueueTests(TestContext context)
|
|||||||
queue.IsPaused = true;
|
queue.IsPaused = true;
|
||||||
|
|
||||||
var path = Path.Combine(context.CreateTempDirectory(), "uploader-queue.json");
|
var path = Path.Combine(context.CreateTempDirectory(), "uploader-queue.json");
|
||||||
QueueStore.Write(path, QueueStore.Serialize(queue));
|
File.WriteAllBytes(path, QueueStore.Serialize(queue));
|
||||||
var restored = new UploadQueue();
|
var restored = new UploadQueue();
|
||||||
QueueStore.Load(path, restored);
|
QueueStore.Load(path, restored);
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ public sealed class UploadQueueTests(TestContext context)
|
|||||||
queue.Items[1].State = UploadItemState.Hashing;
|
queue.Items[1].State = UploadItemState.Hashing;
|
||||||
|
|
||||||
var path = Path.Combine(context.CreateTempDirectory(), "q.json");
|
var path = Path.Combine(context.CreateTempDirectory(), "q.json");
|
||||||
QueueStore.Write(path, QueueStore.Serialize(queue));
|
File.WriteAllBytes(path, QueueStore.Serialize(queue));
|
||||||
var restored = new UploadQueue();
|
var restored = new UploadQueue();
|
||||||
QueueStore.Load(path, restored);
|
QueueStore.Load(path, restored);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user