diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 7ad03de8eae..49dce58f4e4 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -418,12 +418,6 @@ jobs:
framework: ["net8.0", "net10.0"]
steps:
- uses: actions/checkout@v4
- - name: Start Consul
- run: |
- docker run -d --name consul -p 8500:8500 -p 8600:8600/tcp -p 8600:8600/udp \
- hashicorp/consul:1.19 agent -dev -client=0.0.0.0
- - name: Wait for Consul
- run: sleep 5
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
@@ -436,14 +430,6 @@ jobs:
--logger "trx;LogFileName=test_results_${{ matrix.provider }}_${{ matrix.framework }}.trx"
--
-parallel none -noshadow
- env:
-# [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Not a secret")]
-# [SuppressMessage("Microsoft.Security", "CSCAN0090:ConfigFile", Justification="Not a secret")]
-# [SuppressMessage("Microsoft.Security", "CSCAN0220:DefaultPasswordContexts", Justification="Not a secret")]
- ORLEANSCONSULCONNECTIONSTRING: "http://localhost:8500"
- - name: Clean up Consul container
- if: always()
- run: docker rm -f consul
- name: Archive Test Results
if: always()
uses: actions/upload-artifact@v4
@@ -609,7 +595,7 @@ jobs:
- name: Test
run: dotnet test
--framework ${{ matrix.framework }}
- --filter "Category=${{ matrix.suite }}"
+ --filter "Category=${{ matrix.suite }}&Category!=Consul"
--blame-hang-timeout 10m
--logger "trx;LogFileName=test_results_${{ matrix.suite }}_${{ matrix.framework }}.trx"
--
diff --git a/Directory.Packages.props b/Directory.Packages.props
index a84cc1e8590..8222c0a0372 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -104,6 +104,7 @@
+
diff --git a/test/Extensions/Consul.Tests/Consul.Tests.csproj b/test/Extensions/Consul.Tests/Consul.Tests.csproj
index e4c4e01944b..228f1c15a9b 100644
--- a/test/Extensions/Consul.Tests/Consul.Tests.csproj
+++ b/test/Extensions/Consul.Tests/Consul.Tests.csproj
@@ -6,6 +6,7 @@
+
diff --git a/test/Extensions/Consul.Tests/ConsulTestUtils.cs b/test/Extensions/Consul.Tests/ConsulTestUtils.cs
index 0fc110f9d55..d903fedef72 100644
--- a/test/Extensions/Consul.Tests/ConsulTestUtils.cs
+++ b/test/Extensions/Consul.Tests/ConsulTestUtils.cs
@@ -1,5 +1,4 @@
-using System.Net;
-using TestExtensions;
+using Testcontainers.Consul;
using Xunit;
namespace Consul.Tests
@@ -9,7 +8,25 @@ namespace Consul.Tests
///
public static class ConsulTestUtils
{
- public static readonly string ConsulConnectionString = TestDefaultConfiguration.ConsulConnectionString;
+ private static readonly ConsulContainer _container = new ConsulBuilder()
+ .WithImage("hashicorp/consul:1.19")
+ .WithCreateParameterModifier(parameters =>
+ {
+ if (parameters.HostConfig is not null)
+ {
+ parameters.HostConfig.CapAdd = ["IPC_LOCK"];
+ }
+ })
+ .Build();
+
+ public static string ConsulConnectionString
+ {
+ get
+ {
+ EnsureConsul();
+ return _container.GetBaseAddress();
+ }
+ }
private static readonly Lazy EnsureConsulLazy = new Lazy(() => EnsureConsulAsync().Result);
public static void EnsureConsul()
@@ -20,17 +37,10 @@ public static void EnsureConsul()
public static async Task EnsureConsulAsync()
{
- if (string.IsNullOrWhiteSpace(ConsulConnectionString))
- {
- return false;
- }
-
try
{
- var client = new HttpClient();
- client.Timeout = TimeSpan.FromSeconds(15);
- var response = await client.GetAsync($"{ConsulConnectionString}/v1/health/service/consul?pretty");
- return response.StatusCode == HttpStatusCode.OK;
+ await _container.StartAsync();
+ return true;
}
catch (HttpRequestException)
{