Skip to content

Commit

Permalink
RavenDB-21594 marking tests with RavenTheory
Browse files Browse the repository at this point in the history
  • Loading branch information
ppekrol committed Nov 23, 2023
1 parent 7df1a42 commit e1e4f58
Showing 1 changed file with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2949,7 +2949,7 @@ public async Task ShouldCancelTheBackupRunningIfItGotDisabledWhileRunning()
}
}

// Performing backup Delay to the time:
// Performing backup Delay to the time:
[InlineData(1)] // until the next scheduled backup time.
[InlineData(5)] // after the next scheduled backup.
[Theory, Trait("Category", "Smuggler")]
Expand All @@ -2970,7 +2970,7 @@ public async Task ShouldProperlyPlaceOriginalBackupTimePropertyWithDelay(int del

var config = Backup.CreateBackupConfiguration(backupPath, fullBackupFrequency: fullBackupFrequency);
var taskId = await Backup.UpdateConfigAndRunBackupAsync(server, config, store, opStatus: OperationStatus.InProgress);

// Let's delay the backup task
var taskBackupInfo = await store.Maintenance.SendAsync(new GetOngoingTaskInfoOperation(taskId, OngoingTaskType.Backup)) as OngoingTaskBackup;
Assert.NotNull(taskBackupInfo);
Expand Down Expand Up @@ -3002,7 +3002,7 @@ await WaitForValueAsync(async () =>
Assert.NotNull(nextFullBackup);

Assert.Equal(backupStatus.OriginalBackupTime,
delayUntil < nextFullBackup
delayUntil < nextFullBackup
? taskBackupInfo.OnGoingBackup.StartTime // until the next scheduled backup time.
: nextFullBackup.Value.ToUniversalTime()); // after the next scheduled backup.
}
Expand Down Expand Up @@ -3107,7 +3107,7 @@ await WaitForValueAsync(async () =>
}, true);
Assert.Null(afterDelayTaskBackupInfo.LastFullBackup);
Assert.True(afterDelayTaskBackupInfo.NextBackup.TimeSpan > delayDuration.Subtract(TimeSpan.FromMilliseconds(sw.ElapsedMilliseconds + 1_000)) &&
afterDelayTaskBackupInfo.NextBackup.TimeSpan <= delayDuration,
afterDelayTaskBackupInfo.NextBackup.TimeSpan <= delayDuration,
$"NextBackup in: `{afterDelayTaskBackupInfo.NextBackup.TimeSpan}`, delayDuration with tolerance: `{delayDuration.Subtract(TimeSpan.FromMilliseconds(sw.ElapsedMilliseconds + 1_000))}`, " +
$"delayDuration: `{delayDuration}`");

Expand Down Expand Up @@ -3259,7 +3259,7 @@ public async Task ShouldScheduleNextBackupAfterServerRestartCorrectly()
database.PeriodicBackupRunner.ForTestingPurposesOnly().OnBackupTaskRunHoldBackupExecution = new TaskCompletionSource<object>();

await Backup.RunBackupAsync(leaderServer, taskId, leaderStore, opStatus: OperationStatus.InProgress);

// Let's delay the backup task to 1 hour
var delayDuration = TimeSpan.FromHours(1);
var sw = Stopwatch.StartNew();
Expand Down Expand Up @@ -3338,11 +3338,11 @@ public async Task EveryNodeHasDelayInMemory()
var notLeaderServer = nodes.First(x => x != leaderServer);

using (var leaderStore = new DocumentStore
{
Urls = new[] { leaderServer.WebUrl },
Conventions = new DocumentConventions { DisableTopologyUpdates = true },
Database = databaseName
})
{
Urls = new[] { leaderServer.WebUrl },
Conventions = new DocumentConventions { DisableTopologyUpdates = true },
Database = databaseName
})
{
leaderStore.Initialize();

Expand All @@ -3364,22 +3364,22 @@ public async Task EveryNodeHasDelayInMemory()
Assert.NotNull(onGoingTaskInfo);
var runningBackupTaskId = onGoingTaskInfo.OnGoingBackup.RunningBackupTaskId;
await leaderStore.Maintenance.SendAsync(new DelayBackupOperation(runningBackupTaskId, delayDuration));

// We'll check another (not leader) nodes in cluster
foreach (var server in nodes.Where(node => node != leaderServer))
{
using (var store = new DocumentStore
{
Urls = new[] { server.WebUrl },
Conventions = new DocumentConventions { DisableTopologyUpdates = true },
Database = databaseName
})
{
Urls = new[] { server.WebUrl },
Conventions = new DocumentConventions { DisableTopologyUpdates = true },
Database = databaseName
})
{
store.Initialize();

var documentDatabase = await server.ServerStore.DatabasesLandlord.TryGetOrCreateResourceStore(store.Database).ConfigureAwait(false);
documentDatabase.PeriodicBackupRunner.ForTestingPurposesOnly().BackupStatusFromMemoryOnly = true;

PeriodicBackupStatus inMemoryStatus = null;
WaitForValue(() =>
{
Expand Down Expand Up @@ -3407,7 +3407,7 @@ public async Task ShouldDelayOnCurrentNodeIfClusterDown()

var (nodes, leaderServer) = await CreateRaftCluster(clusterSize);
await CreateDatabaseInCluster(databaseName, clusterSize, leaderServer.WebUrl);

using (var leaderStore = new DocumentStore
{
Urls = new[] { leaderServer.WebUrl },
Expand All @@ -3417,20 +3417,20 @@ public async Task ShouldDelayOnCurrentNodeIfClusterDown()
{
leaderStore.Initialize();
await Backup.FillClusterDatabaseWithRandomDataAsync(databaseSizeInMb: 10, leaderStore, clusterSize);

var responsibleDatabase = await leaderServer.ServerStore.DatabasesLandlord.TryGetOrCreateResourceStore(leaderStore.Database).ConfigureAwait(false);
Assert.NotNull(responsibleDatabase);
responsibleDatabase.PeriodicBackupRunner.ForTestingPurposesOnly().OnBackupTaskRunHoldBackupExecution = new TaskCompletionSource<object>();

var config = Backup.CreateBackupConfiguration(backupPath, fullBackupFrequency: "* * * * *", mentorNode: leaderServer.ServerStore.NodeTag);
var taskId = await Backup.UpdateConfigAndRunBackupAsync(leaderServer, config, leaderStore, opStatus: OperationStatus.InProgress);

// Simulate Cluster Down state
foreach (var node in nodes.Where(x => x != leaderServer))
{
await DisposeAndRemoveServer(node);
await DisposeAndRemoveServer(node);
}

// Let's delay the backup task to 1 hour
var onGoingTaskInfo = await leaderStore.Maintenance.SendAsync(new GetOngoingTaskInfoOperation(taskId, OngoingTaskType.Backup)) as OngoingTaskBackup;
Assert.NotNull(onGoingTaskInfo);
Expand All @@ -3441,7 +3441,7 @@ public async Task ShouldDelayOnCurrentNodeIfClusterDown()

// Check that there is no ongoing backup and new task scheduled properly
onGoingTaskInfo = null;
await WaitForValueAsync( async () =>
await WaitForValueAsync(async () =>
{
onGoingTaskInfo = await leaderStore.Maintenance.SendAsync(new GetOngoingTaskInfoOperation(taskId, OngoingTaskType.Backup)) as OngoingTaskBackup;
return onGoingTaskInfo is { OnGoingBackup: null };
Expand All @@ -3458,7 +3458,7 @@ await WaitForValueAsync( async () =>
public async Task NumberOfCurrentlyRunningBackupsShouldBeCorrectAfterBackupTaskDelay()
{
var backupPath = NewDataPath(suffix: "BackupFolder");

using (var store = GetDocumentStore())
{
using (var session = store.OpenAsyncSession())
Expand All @@ -3480,7 +3480,7 @@ public async Task NumberOfCurrentlyRunningBackupsShouldBeCorrectAfterBackupTaskD
using (context.OpenReadTransaction())
{
AssertNumberOfConcurrentBackups(expectedNumber: 1);

// Let's delay the backup task to 1 hour
var delayDuration = TimeSpan.FromHours(1);
await store.Maintenance.SendAsync(new DelayBackupOperation(taskBackupInfo.OnGoingBackup.RunningBackupTaskId, delayDuration));
Expand All @@ -3489,7 +3489,7 @@ public async Task NumberOfCurrentlyRunningBackupsShouldBeCorrectAfterBackupTaskD

void AssertNumberOfConcurrentBackups(int expectedNumber)
{
int concurrentBackups = WaitForValue( () => Server.ServerStore.ConcurrentBackupsCounter.CurrentNumberOfRunningBackups,
int concurrentBackups = WaitForValue(() => Server.ServerStore.ConcurrentBackupsCounter.CurrentNumberOfRunningBackups,
expectedVal: expectedNumber,
timeout: Convert.ToInt32(TimeSpan.FromMinutes(1).TotalMilliseconds),
interval: Convert.ToInt32(TimeSpan.FromSeconds(1).TotalMilliseconds));
Expand All @@ -3499,7 +3499,7 @@ void AssertNumberOfConcurrentBackups(int expectedNumber)
}
}
}

[Fact, Trait("Category", "Smuggler")]
public async Task ShouldRearrangeTheBackupTimer_IfItGot_ActiveByOtherNode_Then_ActiveByCurrentNode_WhileRunning()
{
Expand Down Expand Up @@ -3681,7 +3681,7 @@ await session.StoreAsync(new Address
}
}

[Theory, Trait("Category", "Smuggler")]
[RavenTheory(RavenTestCategory.BackupExportImport)]
[InlineData(BackupType.Snapshot)]
[InlineData(BackupType.Backup)]
public async Task can_backup_incremental_and_restore_with_subscription(BackupType backupType)
Expand Down Expand Up @@ -3762,7 +3762,7 @@ await store.Subscriptions.CreateAsync(new SubscriptionCreationOptions<Order>

private readonly TimeSpan _reasonableWaitTime = Debugger.IsAttached ? TimeSpan.FromMinutes(5) : TimeSpan.FromSeconds(60);

[Theory, Trait("Category", "Smuggler")]
[RavenTheory(RavenTestCategory.BackupExportImport)]
[InlineData(BackupType.Snapshot)]
public async Task can_incremental_snapshot_and_restore_with_subscription(BackupType backupType)
{
Expand Down Expand Up @@ -3852,7 +3852,7 @@ public async Task can_incremental_snapshot_and_restore_with_subscription(BackupT
}
}

[Theory, Trait("Category", "Smuggler")]
[RavenTheory(RavenTestCategory.BackupExportImport)]
[InlineData(BackupType.Snapshot)]
public async Task can_snapshot_and_restore_with_subscription(BackupType backupType)
{
Expand Down Expand Up @@ -3918,7 +3918,7 @@ public async Task can_snapshot_and_restore_with_subscription(BackupType backupTy
}
}

[Theory, Trait("Category", "Smuggler")]
[RavenTheory(RavenTestCategory.BackupExportImport)]
[InlineData(BackupType.Snapshot)]
[InlineData(BackupType.Backup)]
public async Task can_backup_and_restore_with_subscription(BackupType backupType)
Expand Down

0 comments on commit e1e4f58

Please sign in to comment.