From b5d645983ef33e6208d958347b39fca8be9aeb76 Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Wed, 11 Dec 2024 18:23:14 -0800 Subject: [PATCH] Set TestTfmsInParallel fals for Integration tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This should fix the toxiproxy issues once and for all 🤞 --- projects/Test/Integration/Integration.csproj | 1 + projects/Test/Integration/TestToxiproxy.cs | 2 +- projects/Test/Integration/ToxiproxyManager.cs | 20 +++++++++---------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/projects/Test/Integration/Integration.csproj b/projects/Test/Integration/Integration.csproj index 31b69369f..bf8eb507c 100644 --- a/projects/Test/Integration/Integration.csproj +++ b/projects/Test/Integration/Integration.csproj @@ -17,6 +17,7 @@ true true 12.0 + false diff --git a/projects/Test/Integration/TestToxiproxy.cs b/projects/Test/Integration/TestToxiproxy.cs index c94165444..1629dc69b 100644 --- a/projects/Test/Integration/TestToxiproxy.cs +++ b/projects/Test/Integration/TestToxiproxy.cs @@ -62,7 +62,7 @@ public override Task InitializeAsync() Assert.Null(_channel); _toxiproxyManager = new ToxiproxyManager(_testDisplayName, IsRunningInCI, IsWindows); - _proxyPort = _toxiproxyManager.ProxyPort; + _proxyPort = ToxiproxyManager.ProxyPort; return _toxiproxyManager.InitializeAsync(); } diff --git a/projects/Test/Integration/ToxiproxyManager.cs b/projects/Test/Integration/ToxiproxyManager.cs index 21b81245b..a03443663 100644 --- a/projects/Test/Integration/ToxiproxyManager.cs +++ b/projects/Test/Integration/ToxiproxyManager.cs @@ -1,7 +1,6 @@ using System; using System.Globalization; using System.Net; -using System.Threading; using System.Threading.Tasks; using Test; using Toxiproxy.Net; @@ -11,12 +10,10 @@ namespace Integration { public class ToxiproxyManager : IAsyncDisposable { + public const ushort ProxyPort = 55672; private const string ProxyNamePrefix = "rmq"; - private const ushort ProxyPortStart = 55669; - private static int s_proxyPort = ProxyPortStart; private readonly string _testDisplayName; - private readonly int _proxyPort; private readonly Connection _proxyConnection; private readonly Client _proxyClient; private readonly Proxy _proxy; @@ -32,8 +29,6 @@ public ToxiproxyManager(string testDisplayName, bool isRunningInCI, bool isWindo _testDisplayName = testDisplayName; - _proxyPort = Interlocked.Increment(ref s_proxyPort); - /* * Note: * Do NOT set resetAllToxicsAndProxiesOnClose to true, because it will @@ -46,13 +41,13 @@ public ToxiproxyManager(string testDisplayName, bool isRunningInCI, bool isWindo _proxy = new Proxy { Enabled = true, - Listen = $"{IPAddress.Loopback}:{_proxyPort}", + Listen = $"{IPAddress.Loopback}:{ProxyPort}", Upstream = $"{IPAddress.Loopback}:5672", }; if (isRunningInCI) { - _proxy.Listen = $"0.0.0.0:{_proxyPort}"; + _proxy.Listen = $"0.0.0.0:{ProxyPort}"; // GitHub Actions if (false == isWindows) @@ -66,11 +61,14 @@ public ToxiproxyManager(string testDisplayName, bool isRunningInCI, bool isWindo } } - public int ProxyPort => _proxyPort; - public async Task InitializeAsync() { - string proxyName = $"{ProxyNamePrefix}-{_testDisplayName}-{Util.Now}-{Guid.NewGuid()}"; + /* + * Note: since all Toxiproxy tests are in the same test class, they will run sequentially, + * so we can use 55672 for the listen port. In addition, TestTfmsInParallel is set to false + * so we know only one set of integration tests are running at a time + */ + string proxyName = $"{ProxyNamePrefix}-{_testDisplayName}-{Util.Now}"; _proxy.Name = proxyName; ushort retryCount = 5;