Files
Chronos/tests/Chronos.App.Tests/Setup/ScratchRegistry.cs
T
Alby96andClaude Opus 5.5 c3273b7da5 test: serialise setup registry scratch keys and refresh the copy plan baselines
The setup tests running in parallel shared HKCU\Software\Chronos.Tests and each
removed it once it looked empty; one test's cleanup could race another's key
creation and fail ReplacingTheLegacyUploaderMovesItsSignInEntryAndKeepsItTurnedOff
in a whole-suite run. ScratchRegistry now creates each scratch key and removes
the parent under one lock.

The Plan and Blocked compare captures now count both server projects coming
to this PC (Vertical and Slow pan, as the Projects part lists them); the old
baselines still showed one.

Refs #73

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 22:48:17 +01:00

36 lines
1.3 KiB
C#

using Microsoft.Win32;
namespace Chronos.App.Tests.Setup;
/// <summary>
/// Scratch keys under HKCU\Software\Chronos.Tests for the setup tests, which run in parallel: a key is created, and the
/// shared parent removed once empty, under one lock, so one test's cleanup never deletes the parent while another test
/// is creating its key under it.
/// </summary>
internal static class ScratchRegistry
{
private const string Root = @"Software\Chronos.Tests";
private static readonly Lock Gate = new();
/// <summary>Creates a new empty scratch key and returns its path under HKCU.</summary>
public static string Create()
{
var keyPath = Root + @"\" + Guid.NewGuid().ToString("N");
lock (Gate) Registry.CurrentUser.CreateSubKey(keyPath, writable: true).Dispose();
return keyPath;
}
/// <summary>Deletes a scratch key made by <see cref="Create"/>, and the shared parent too once it is empty.</summary>
public static void Delete(string keyPath)
{
lock (Gate)
{
Registry.CurrentUser.DeleteSubKeyTree(keyPath, throwOnMissingSubKey: false);
bool empty;
using (var tests = Registry.CurrentUser.OpenSubKey(Root)) empty = tests is { SubKeyCount: 0, ValueCount: 0 };
if (empty) Registry.CurrentUser.DeleteSubKey(Root, throwOnMissingSubKey: false);
}
}
}