mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 13:11:10 +00:00
Removes flaky remainin cancellation token integration tests
This commit is contained in:
1 parent
5806b768c2
commit
afb8773005
3 files changed
-212
No files matched your search
-133
@@ -362,52 +362,6 @@ public class DirectoriesControllerTests : IClassFixture<LuminaApiFactory>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task GetDirectoryTree_WhenCancellationIsRequested_ShouldStopYieldingResults()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
FileSystemStructureFixture fileSystemFixture = new();
|
|
||||||
string testPath = fileSystemFixture.CreateFileSystemStructure();
|
|
||||||
|
|
||||||
bool includeFiles = true;
|
|
||||||
bool includeHiddenElements = false;
|
|
||||||
CancellationTokenSource cts = new();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Act
|
|
||||||
Task<HttpResponseMessage> getDirectoryTreeTask = _client.GetAsync(
|
|
||||||
$"/api/v1/directories/get-directory-tree?path={Uri.EscapeDataString(testPath)}&includeFiles={includeFiles}&includeHiddenElements={includeHiddenElements}",
|
|
||||||
cts.Token
|
|
||||||
);
|
|
||||||
|
|
||||||
// simulate cancellation before the request completes
|
|
||||||
cts.Cancel();
|
|
||||||
|
|
||||||
HttpResponseMessage? response = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
response = await getDirectoryTreeTask;
|
|
||||||
}
|
|
||||||
catch (TaskCanceledException)
|
|
||||||
{
|
|
||||||
// expected when the task is cancelled, suppress the exception to continue the test
|
|
||||||
}
|
|
||||||
// Assert
|
|
||||||
response?.StatusCode.Should().Be(HttpStatusCode.OK, "The cancellation should occur gracefully on the server side");
|
|
||||||
|
|
||||||
// assert that no elements were returned after cancellation
|
|
||||||
if (response != null)
|
|
||||||
using (Stream stream = await response.Content.ReadAsStreamAsync())
|
|
||||||
using (JsonDocument jsonDoc = await JsonDocument.ParseAsync(stream))
|
|
||||||
jsonDoc.RootElement.GetArrayLength().Should().Be(0, "no elements should be yielded after cancellation");
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
fileSystemFixture.CleanupFileSystemStructure();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task GetTreeDirectories_WhenCalledWithValidPathAndNotIncludeHiddenElements_ShouldReturnTreeDirectoriesWithoutHiddenElements()
|
public async Task GetTreeDirectories_WhenCalledWithValidPathAndNotIncludeHiddenElements_ShouldReturnTreeDirectoriesWithoutHiddenElements()
|
||||||
{
|
{
|
||||||
@@ -550,51 +504,6 @@ public class DirectoriesControllerTests : IClassFixture<LuminaApiFactory>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task GetTreeDirectories_WhenCancellationIsRequested_ShouldStopYieldingResults()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
FileSystemStructureFixture fileSystemFixture = new();
|
|
||||||
string testPath = fileSystemFixture.CreateFileSystemStructure();
|
|
||||||
|
|
||||||
bool includeHiddenElements = false;
|
|
||||||
CancellationTokenSource cts = new();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Act
|
|
||||||
Task<HttpResponseMessage> getTreeDirectoriesTask = _client.GetAsync(
|
|
||||||
$"/api/v1/directories/get-tree-directories?path={Uri.EscapeDataString(testPath)}&includeHiddenElements={includeHiddenElements}",
|
|
||||||
cts.Token
|
|
||||||
);
|
|
||||||
|
|
||||||
// simulate cancellation before the request completes
|
|
||||||
cts.Cancel();
|
|
||||||
|
|
||||||
HttpResponseMessage? response = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
response = await getTreeDirectoriesTask;
|
|
||||||
}
|
|
||||||
catch (TaskCanceledException)
|
|
||||||
{
|
|
||||||
// expected when the task is cancelled, suppress the exception to continue the test
|
|
||||||
}
|
|
||||||
// Assert
|
|
||||||
response?.StatusCode.Should().Be(HttpStatusCode.OK, "The cancellation should occur gracefully on the server side");
|
|
||||||
|
|
||||||
// assert that no elements were returned after cancellation
|
|
||||||
if (response != null)
|
|
||||||
using (Stream stream = await response.Content.ReadAsStreamAsync())
|
|
||||||
using (JsonDocument jsonDoc = await JsonDocument.ParseAsync(stream))
|
|
||||||
jsonDoc.RootElement.GetArrayLength().Should().Be(0, "no elements should be yielded after cancellation");
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
fileSystemFixture.CleanupFileSystemStructure();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task GetDirectories_WhenCalledWithValidPathAndNotIncludeHiddenElements_ShouldReturnDirectoriesWithoutHiddenElements()
|
public async Task GetDirectories_WhenCalledWithValidPathAndNotIncludeHiddenElements_ShouldReturnDirectoriesWithoutHiddenElements()
|
||||||
{
|
{
|
||||||
@@ -732,47 +641,5 @@ public class DirectoriesControllerTests : IClassFixture<LuminaApiFactory>
|
|||||||
fileSystemFixture.CleanupFileSystemStructure();
|
fileSystemFixture.CleanupFileSystemStructure();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task GetDirectories_WhenCancellationIsRequested_ShouldStopYieldingResults()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
FileSystemStructureFixture fileSystemFixture = new();
|
|
||||||
string testPath = fileSystemFixture.CreateFileSystemStructure();
|
|
||||||
|
|
||||||
bool includeHiddenElements = false;
|
|
||||||
CancellationTokenSource cts = new();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Act
|
|
||||||
Task<HttpResponseMessage> getDirectoriesTask = _client.GetAsync($"/api/v1/directories/get-directories?path={Uri.EscapeDataString(testPath)}&includeHiddenElements={includeHiddenElements}", cts.Token);
|
|
||||||
|
|
||||||
// simulate cancellation before the request completes
|
|
||||||
cts.Cancel();
|
|
||||||
|
|
||||||
HttpResponseMessage? response = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
response = await getDirectoriesTask;
|
|
||||||
}
|
|
||||||
catch (TaskCanceledException)
|
|
||||||
{
|
|
||||||
// expected when the task is cancelled, suppress the exception to continue the test
|
|
||||||
}
|
|
||||||
// Assert
|
|
||||||
response?.StatusCode.Should().Be(HttpStatusCode.OK, "The cancellation should occur gracefully on the server side");
|
|
||||||
|
|
||||||
// assert that no elements were returned after cancellation
|
|
||||||
if (response != null)
|
|
||||||
using (Stream stream = await response.Content.ReadAsStreamAsync())
|
|
||||||
using (JsonDocument jsonDoc = await JsonDocument.ParseAsync(stream))
|
|
||||||
jsonDoc.RootElement.GetArrayLength().Should().Be(0, "no elements should be yielded after cancellation");
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
fileSystemFixture.CleanupFileSystemStructure();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
-34
@@ -81,39 +81,5 @@ public class DrivesControllerTests : IClassFixture<LuminaApiFactory>
|
|||||||
firstDrive.ItemType.Should().Be(FileSystemItemType.Root);
|
firstDrive.ItemType.Should().Be(FileSystemItemType.Root);
|
||||||
drives.Count.Should().BeGreaterThanOrEqualTo(1);
|
drives.Count.Should().BeGreaterThanOrEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task GetDrives_WhenCancellationIsRequested_ShouldStopYieldingResults()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
CancellationTokenSource cts = new();
|
|
||||||
|
|
||||||
// Act
|
|
||||||
Task<HttpResponseMessage> getDrivesTask = _client.GetAsync(
|
|
||||||
$"/api/v1/drives/get-drives",
|
|
||||||
cts.Token
|
|
||||||
);
|
|
||||||
|
|
||||||
// simulate cancellation before the request completes
|
|
||||||
cts.Cancel();
|
|
||||||
|
|
||||||
HttpResponseMessage? response = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
response = await getDrivesTask;
|
|
||||||
}
|
|
||||||
catch (TaskCanceledException)
|
|
||||||
{
|
|
||||||
// expected when the task is cancelled, suppress the exception to continue the test
|
|
||||||
}
|
|
||||||
// Assert
|
|
||||||
response?.StatusCode.Should().Be(HttpStatusCode.OK, "The cancellation should occur gracefully on the server side");
|
|
||||||
|
|
||||||
// assert that no elements were returned after cancellation
|
|
||||||
if (response != null)
|
|
||||||
using (Stream stream = await response.Content.ReadAsStreamAsync())
|
|
||||||
using (JsonDocument jsonDoc = await JsonDocument.ParseAsync(stream))
|
|
||||||
jsonDoc.RootElement.GetArrayLength().Should().Be(0, "no elements should be yielded after cancellation");
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
-45
@@ -331,50 +331,5 @@ public class FilesControllerTests : IClassFixture<LuminaApiFactory>
|
|||||||
fileSystemFixture.CleanupFileSystemStructure();
|
fileSystemFixture.CleanupFileSystemStructure();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task GetFiles_WhenCancellationIsRequested_ShouldStopYieldingResults()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
FileSystemStructureFixture fileSystemFixture = new();
|
|
||||||
string testPath = fileSystemFixture.CreateFileSystemStructure();
|
|
||||||
|
|
||||||
bool includeHiddenElements = false;
|
|
||||||
CancellationTokenSource cts = new();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Act
|
|
||||||
Task<HttpResponseMessage> getTreeFilesTask = _client.GetAsync(
|
|
||||||
$"/api/v1/files/get-files?path={Uri.EscapeDataString(testPath)}&includeHiddenElements={includeHiddenElements}",
|
|
||||||
cts.Token
|
|
||||||
);
|
|
||||||
|
|
||||||
// simulate cancellation before the request completes
|
|
||||||
cts.Cancel();
|
|
||||||
|
|
||||||
HttpResponseMessage? response = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
response = await getTreeFilesTask;
|
|
||||||
}
|
|
||||||
catch (TaskCanceledException)
|
|
||||||
{
|
|
||||||
// expected when the task is cancelled, suppress the exception to continue the test
|
|
||||||
}
|
|
||||||
// Assert
|
|
||||||
response?.StatusCode.Should().Be(HttpStatusCode.OK, "The cancellation should occur gracefully on the server side");
|
|
||||||
|
|
||||||
// assert that no elements were returned after cancellation
|
|
||||||
if (response != null)
|
|
||||||
using (Stream stream = await response.Content.ReadAsStreamAsync())
|
|
||||||
using (JsonDocument jsonDoc = await JsonDocument.ParseAsync(stream))
|
|
||||||
jsonDoc.RootElement.GetArrayLength().Should().Be(0, "no elements should be yielded after cancellation");
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
fileSystemFixture.CleanupFileSystemStructure();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user