From 1c97c3960f4aee9461e47bd3824aa03a00f13b34 Mon Sep 17 00:00:00 2001 From: Guillaume Gnaegi <58469901+ggnaegi@users.noreply.github.com> Date: Sun, 24 Sep 2023 20:16:46 +0200 Subject: [PATCH] Trying yet another strategy --- .../ConfigurationReloadTests.cs | 3 +-- test/Ocelot.AcceptanceTests/Steps.cs | 26 +++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/test/Ocelot.AcceptanceTests/ConfigurationReloadTests.cs b/test/Ocelot.AcceptanceTests/ConfigurationReloadTests.cs index a9656ce68..faf528dad 100644 --- a/test/Ocelot.AcceptanceTests/ConfigurationReloadTests.cs +++ b/test/Ocelot.AcceptanceTests/ConfigurationReloadTests.cs @@ -42,8 +42,7 @@ public void should_reload_config_on_change() this.Given(x => _steps.GivenThereIsAConfiguration(_initialConfig)) .And(x => _steps.GivenOcelotIsRunningReloadingConfig(true)) .And(x => _steps.GivenThereIsAConfiguration(_anotherConfig)) - .And(x => _steps.GivenIWait(7500)) - .And(x => _steps.ThenConfigShouldBe(_anotherConfig)) + .And(x => _steps.ThenConfigShouldBeWithTimeout(_anotherConfig, 10000)) .BDDfy(); } diff --git a/test/Ocelot.AcceptanceTests/Steps.cs b/test/Ocelot.AcceptanceTests/Steps.cs index e585b1c8b..1499995a9 100644 --- a/test/Ocelot.AcceptanceTests/Steps.cs +++ b/test/Ocelot.AcceptanceTests/Steps.cs @@ -65,15 +65,37 @@ public class Steps : IDisposable public async Task ThenConfigShouldBe(FileConfiguration fileConfig) { var internalConfigCreator = _ocelotServer.Host.Services.GetService(); - var internalConfigRepo = _ocelotServer.Host.Services.GetService(); - var internalConfig = internalConfigRepo.Get(); + var internalConfig = internalConfigRepo.Get(); var config = await internalConfigCreator.Create(fileConfig); internalConfig.Data.RequestId.ShouldBe(config.Data.RequestId); } + public async Task ThenConfigShouldBeWithTimeout(FileConfiguration fileConfig, int timeoutMs) + { + var totalMs = 0; + var result = false; + + while (!result && totalMs < timeoutMs) + { + result = await Wait.WaitFor(1000).Until(async () => + { + var internalConfigCreator = _ocelotServer.Host.Services.GetService(); + var internalConfigRepo = _ocelotServer.Host.Services.GetService(); + + var internalConfig = internalConfigRepo.Get(); + var config = await internalConfigCreator.Create(fileConfig); + + return internalConfig.Data.RequestId == config.Data.RequestId; + }); + totalMs += 1000; + } + + result.ShouldBe(true); + } + public async Task StartFakeOcelotWithWebSockets() { _ocelotBuilder = new WebHostBuilder();