Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="coverlet.collector" Version="10.0.1" />
<PackageVersion Include="Docker.DotNet" Version="3.125.15" />
<PackageVersion Include="Docker.DotNet.Enhanced" Version="4.3.3" />
<PackageVersion Include="DotNet.ReproducibleBuilds" Version="2.0.5" />
<PackageVersion Include="LibGit2Sharp" Version="0.30.0" />
<PackageVersion Include="Meziantou.Analyzer" Version="3.0.266" />
Expand All @@ -22,6 +22,7 @@
<PackageVersion Include="NUnit3TestAdapter" Version="6.3.0" />
<PackageVersion Include="Polly" Version="8.8.0" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
<PackageVersion Include="Testcontainers" Version="4.15.0" />
<PackageVersion Include="Verify.NUnit" Version="32.0.1" />
<PackageVersion Include="YamlDotNet" Version="16.3.0" />
</ItemGroup>
Expand Down
358 changes: 178 additions & 180 deletions NGitLab.Tests/Docker/GitLabDockerContainer.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion NGitLab.Tests/Docker/GitLabTestContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static async Task<GitLabTestContext> CreateAsync()
// Disable proxy
Environment.SetEnvironmentVariable("http_proxy", "", EnvironmentVariableTarget.Process);
Environment.SetEnvironmentVariable("https_proxy", "", EnvironmentVariableTarget.Process);
var container = await GitLabDockerContainer.GetOrCreateInstance().ConfigureAwait(false);
var container = await GitLabDockerContainer.GetOrCreateInstanceAsync().ConfigureAwait(false);
return new GitLabTestContext(container);
}

Expand Down
5 changes: 4 additions & 1 deletion NGitLab.Tests/Docker/GitLabTestContextRequestOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ internal sealed class GitLabTestContextRequestOptions : RequestOptions
public IReadOnlyList<WebRequest> AllRequests => _allRequests;

public GitLabTestContextRequestOptions()
: base(retryCount: 0, retryInterval: TimeSpan.FromSeconds(1), isIncremental: true)
// GitLab occasionally returns a transient 500 right after an async operation (e.g. a project
// delete) is accepted, before its Sidekiq job has actually started. The base ShouldRetry already
// treats 5xx/408 on idempotent (GET/HEAD/OPTIONS) requests as retryable, so give it retries to work with.
: base(retryCount: 5, retryInterval: TimeSpan.FromSeconds(1), isIncremental: true)
{
UserAgent = "NGitLab.Tests/1.0.0";
}
Expand Down
7 changes: 7 additions & 0 deletions NGitLab.Tests/Docker/NGitLabRetryAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;
Expand All @@ -18,6 +19,11 @@ public TestCommand Wrap(TestCommand command)

public class RetryCommand : DelegatingTestCommand
{
// Some failures are caused by GitLab-side operations still settling asynchronously
// (e.g. a Sidekiq deletion job). Retrying instantly gives the server no time to catch up,
// so back off between attempts instead of hammering the same not-yet-resolved state.
private static readonly TimeSpan RetryDelay = TimeSpan.FromSeconds(3);

private readonly int _tryCount;

public RetryCommand(TestCommand innerCommand, int tryCount)
Expand Down Expand Up @@ -46,6 +52,7 @@ public override TestResult Execute(TestExecutionContext context)

if (count > 0)
{
Thread.Sleep(RetryDelay);
context.CurrentResult = context.CurrentTest.MakeTestResult();
context.CurrentRepeatCount++; // increment Retry count for next iteration. will only happen if we are guaranteed another iteration
}
Expand Down
3 changes: 2 additions & 1 deletion NGitLab.Tests/NGitLab.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ProjectReference Include="..\NGitLab\NGitLab.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Docker.DotNet" />
<PackageReference Include="Docker.DotNet.Enhanced" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NuGet.Versioning" />
<PackageReference Include="NUnit" />
Expand All @@ -18,6 +18,7 @@
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="NSubstitute" />
<PackageReference Include="Polly" />
<PackageReference Include="Testcontainers" />
<PackageReference Include="coverlet.collector">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
8 changes: 4 additions & 4 deletions NGitLab.Tests/ProjectsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public async Task CreateUpdateDelete(bool initiallySetTagsInsteadOfTopics)
var updatedProject2 = projectClient.Update(createdProject.PathWithNamespace, new ProjectUpdate { Visibility = VisibilityLevel.Internal });
Assert.That(updatedProject2.VisibilityLevel, Is.EqualTo(VisibilityLevel.Internal));

projectClient.Delete(createdProject.Id);
await projectClient.PermanentlyDeleteAsync(createdProject.Id);
Comment thread
louis-z marked this conversation as resolved.
}

[Test]
Expand Down Expand Up @@ -701,8 +701,8 @@ public async Task ForkProject()

Assert.That(mr.AllowCollaboration, Is.True);

projectClient.Delete(forkedProject.Id);
projectClient.Delete(createdProject.Id);
await projectClient.PermanentlyDeleteAsync(forkedProject.Id);
await projectClient.PermanentlyDeleteAsync(createdProject.Id);
}

[Test]
Expand Down Expand Up @@ -810,7 +810,7 @@ public async Task CreateProjectWithSquashOption(SquashOption? inputSquashOption)
var expectedSquashOption = inputSquashOption ?? SquashOption.DefaultOff;
Assert.That(createdProject.SquashOption, Is.EqualTo(expectedSquashOption));

projectClient.Delete(createdProject.Id);
await projectClient.PermanentlyDeleteAsync(createdProject.Id);
}

[Test]
Expand Down
10 changes: 9 additions & 1 deletion NGitLab.Tests/SetUpFixture.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using NGitLab.Extensions;
using System.Threading.Tasks;
using NGitLab.Extensions;
using NGitLab.Tests.Docker;
using NUnit.Framework;

namespace NGitLab.Tests;
Expand All @@ -11,4 +13,10 @@ public void RunBeforeAnyTests()
{
FunctionRetryExtensions.Logger = msg => TestContext.Out.WriteLine($"[{TestContext.CurrentContext.Test.FullName}] {msg}");
}

[OneTimeTearDown]
public async Task RunAfterAllTestsAsync()
{
await GitLabDockerContainer.DisposeInstanceAsync().ConfigureAwait(false);
}
}
Loading