private static async Task RunSingleMachineTest(
            Func <OperationContext, IClock, AzureBlobStorageMasterElectionMechanism, Task> runTest,
            IClock?clock = null,
            bool worker  = false)
        {
            clock ??= SystemClock.Instance;

            var logger           = TestGlobal.Logger;
            var context          = new Context(logger);
            var operationContext = new OperationContext(context);

            var fileName = ThreadSafeRandom.RandomAlphanumeric(20);

            var configuration = new AzureBlobStorageMasterElectionMechanismConfiguration()
            {
                Credentials      = AzureBlobStorageCredentials.StorageEmulator,
                IsMasterEligible = !worker,
                // Use a random filename to ensure tests don't interact with eachother
                FileName = fileName,
            };
            var machine = new AzureBlobStorageMasterElectionMechanism(
                configuration,
                M1,
                clock);
            await machine.StartupAsync(operationContext).ThrowIfFailureAsync();

            await machine.CleanupStateAsync(operationContext).ThrowIfFailureAsync();

            await runTest(operationContext, clock, machine);

            await machine.CleanupStateAsync(operationContext).ThrowIfFailureAsync();

            await machine.ShutdownAsync(operationContext).ThrowIfFailureAsync();
        }
        private async Task RunTwoMachinesTest(
            Func <OperationContext, IClock, AzureBlobStorageMasterElectionMechanism, AzureBlobStorageMasterElectionMechanism, Task> runTest,
            IClock?clock      = null,
            bool twoMasters   = false,
            bool allowRetries = false)
        {
            clock ??= SystemClock.Instance;

            var logger           = TestGlobal.Logger;
            var context          = new Context(logger);
            var operationContext = new OperationContext(context);

            var fileName = ThreadSafeRandom.RandomAlphanumeric(20);

            var m1 = new AzureBlobStorageMasterElectionMechanism(
                new AzureBlobStorageMasterElectionMechanismConfiguration()
            {
                Credentials      = AzureBlobStorageCredentials.StorageEmulator,
                IsMasterEligible = true,
                // Use a random filename to ensure tests don't interact with eachother
                FileName = fileName,
            },
                M1,
                clock);

            var m2 = new AzureBlobStorageMasterElectionMechanism(
                new AzureBlobStorageMasterElectionMechanismConfiguration()
            {
                Credentials      = AzureBlobStorageCredentials.StorageEmulator,
                IsMasterEligible = twoMasters,
                // Use a random filename to ensure tests don't interact with eachother
                FileName = fileName,
            },
                M2,
                clock);

            await m1.StartupAsync(operationContext).ThrowIfFailureAsync();

            await m2.StartupAsync(operationContext).ThrowIfFailureAsync();

            await m1.CleanupStateAsync(operationContext).ThrowIfFailureAsync();

            await runTest(operationContext, clock, m1, m2);

            await m1.CleanupStateAsync(operationContext).ThrowIfFailureAsync();

            await m2.ShutdownAsync(operationContext).ThrowIfFailureAsync();

            await m1.ShutdownAsync(operationContext).ThrowIfFailureAsync();
        }