-
Notifications
You must be signed in to change notification settings - Fork 463
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changelog and fix for asset deleter.
- Loading branch information
1 parent
27dcc52
commit 99edcfd
Showing
7 changed files
with
168 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
backend/tools/TestSuite/TestSuite.Shared/Fixtures/ClientExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// ========================================================================== | ||
// Squidex Headless CMS | ||
// ========================================================================== | ||
// Copyright (c) Squidex UG (haftungsbeschraenkt) | ||
// All rights reserved. Licensed under the MIT license. | ||
// ========================================================================== | ||
|
||
using Squidex.ClientLibrary.Management; | ||
|
||
namespace TestSuite | ||
{ | ||
public static class ClientExtensions | ||
{ | ||
public static async Task<bool> WaitForDeletionAsync(this IAssetsClient assetsClient, string app, string id, TimeSpan timeout) | ||
{ | ||
try | ||
{ | ||
using var cts = new CancellationTokenSource(timeout); | ||
|
||
while (!cts.IsCancellationRequested) | ||
{ | ||
try | ||
{ | ||
await assetsClient.GetAssetAsync(app, id, cts.Token); | ||
} | ||
catch (SquidexManagementException ex) when (ex.StatusCode == 404) | ||
{ | ||
return true; | ||
} | ||
|
||
await Task.Delay(200, cts.Token); | ||
} | ||
} | ||
catch (OperationCanceledException) | ||
{ | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public static async Task<IDictionary<string, int>> WaitForTagsAsync(this IAssetsClient assetsClient, string app, string id, TimeSpan timeout) | ||
{ | ||
try | ||
{ | ||
using var cts = new CancellationTokenSource(timeout); | ||
|
||
while (!cts.IsCancellationRequested) | ||
{ | ||
var tags = await assetsClient.GetTagsAsync(app, cts.Token); | ||
|
||
if (tags.TryGetValue(id, out var count) && count > 0) | ||
{ | ||
return tags; | ||
} | ||
|
||
await Task.Delay(200, cts.Token); | ||
} | ||
} | ||
catch (OperationCanceledException) | ||
{ | ||
} | ||
|
||
return await assetsClient.GetTagsAsync(app); | ||
} | ||
|
||
public static async Task<BackupJobDto> WaitForBackupAsync(this IBackupsClient backupsClient, string app, TimeSpan timeout) | ||
{ | ||
try | ||
{ | ||
using var cts = new CancellationTokenSource(timeout); | ||
|
||
while (!cts.IsCancellationRequested) | ||
{ | ||
var backups = await backupsClient.GetBackupsAsync(app, cts.Token); | ||
var backup = backups.Items.Find(x => x.Status == JobStatus.Completed || x.Status == JobStatus.Failed); | ||
|
||
if (backup != null) | ||
{ | ||
return backup; | ||
} | ||
|
||
await Task.Delay(200, cts.Token); | ||
} | ||
} | ||
catch (OperationCanceledException) | ||
{ | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public static async Task<RestoreJobDto> WaitForRestoreAsync(this IBackupsClient backupsClient, Uri url, TimeSpan timeout) | ||
{ | ||
try | ||
{ | ||
using var cts = new CancellationTokenSource(timeout); | ||
|
||
while (!cts.IsCancellationRequested) | ||
{ | ||
var restore = await backupsClient.GetRestoreJobAsync(cts.Token); | ||
|
||
if (restore.Url == url && restore.Status is JobStatus.Completed or JobStatus.Failed) | ||
{ | ||
return restore; | ||
} | ||
|
||
await Task.Delay(200, cts.Token); | ||
} | ||
} | ||
catch (OperationCanceledException) | ||
{ | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |