diff --git a/src/ServiceControl.AcceptanceTests.RavenDB/SetupFixture.cs b/src/ServiceControl.AcceptanceTests.RavenDB/SetupFixture.cs deleted file mode 100644 index 5a24a3417e..0000000000 --- a/src/ServiceControl.AcceptanceTests.RavenDB/SetupFixture.cs +++ /dev/null @@ -1,29 +0,0 @@ -namespace ServiceControl.AcceptanceTests.RavenDB; - -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Threading; -using System.Threading.Tasks; -using NUnit.Framework; - -[SetUpFixture] -public class SetupFixture -{ - [OneTimeSetUp] - public async Task Setup() - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - ServiceBus.Management.Infrastructure.Installers.EventSourceCreator.Create(); - - //There is a delay for this becoming true, tests will fall over if they interleave in the wrong way. - var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60)); - while (!EventLog.SourceExists(ServiceBus.Management.Infrastructure.Installers.EventSourceCreator.SourceName)) - { - cts.Token.ThrowIfCancellationRequested(); - await Task.Delay(500, CancellationToken.None); - } - } - } -} \ No newline at end of file diff --git a/src/ServiceControl.AcceptanceTests/SetupFixture.cs b/src/ServiceControl.AcceptanceTests/SetupFixture.cs new file mode 100644 index 0000000000..55ddf35101 --- /dev/null +++ b/src/ServiceControl.AcceptanceTests/SetupFixture.cs @@ -0,0 +1,42 @@ +namespace ServiceControl.AcceptanceTests; + +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; +using System.Runtime.Versioning; +using System.Threading; +using System.Threading.Tasks; +using NUnit.Framework; +using ServiceBus.Management.Infrastructure.Installers; + +[SetUpFixture] +public class SetupFixture +{ + [OneTimeSetUp] + public async Task Setup() + { + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return; + } + + // Every test runs the setup command, which creates the event source if it is missing. Tests run in + // parallel, so without creating it up front several of them race and all but one fail with + // "Source ServiceControl already exists". + EventSourceCreator.Create(); + + await WaitForSource(EventSourceCreator.SourceName); + } + + //There is a delay for this becoming true, tests will fall over if they interleave in the wrong way. + [SupportedOSPlatform("windows")] + static async Task WaitForSource(string sourceName) + { + var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60)); + while (!EventLog.SourceExists(sourceName)) + { + cts.Token.ThrowIfCancellationRequested(); + await Task.Delay(500, CancellationToken.None); + } + } +} diff --git a/src/ServiceControl.Audit.AcceptanceTests.RavenDB/SetupFixture.cs b/src/ServiceControl.Audit.AcceptanceTests.RavenDB/SetupFixture.cs deleted file mode 100644 index 100af7975a..0000000000 --- a/src/ServiceControl.Audit.AcceptanceTests.RavenDB/SetupFixture.cs +++ /dev/null @@ -1,29 +0,0 @@ -namespace ServiceControl.Audit.AcceptanceTests.RavenDB; - -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Threading; -using System.Threading.Tasks; -using NUnit.Framework; - -[SetUpFixture] -public class SetupFixture -{ - [OneTimeSetUp] - public async Task Setup() - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - Infrastructure.EventSourceCreator.Create(); - - //There is a delay for this becoming true, tests will fall over if they interleave in the wrong way. - var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60)); - while (!EventLog.SourceExists(Infrastructure.EventSourceCreator.SourceName)) - { - cts.Token.ThrowIfCancellationRequested(); - await Task.Delay(500, CancellationToken.None); - } - } - } -} \ No newline at end of file diff --git a/src/ServiceControl.Audit.AcceptanceTests/SetupFixture.cs b/src/ServiceControl.Audit.AcceptanceTests/SetupFixture.cs new file mode 100644 index 0000000000..70acaa0843 --- /dev/null +++ b/src/ServiceControl.Audit.AcceptanceTests/SetupFixture.cs @@ -0,0 +1,42 @@ +namespace ServiceControl.Audit.AcceptanceTests; + +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; +using System.Runtime.Versioning; +using System.Threading; +using System.Threading.Tasks; +using NUnit.Framework; +using ServiceControl.Audit.Infrastructure; + +[SetUpFixture] +public class SetupFixture +{ + [OneTimeSetUp] + public async Task Setup() + { + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return; + } + + // Every test runs the setup command, which creates the event source if it is missing. Tests run in + // parallel, so without creating it up front several of them race and all but one fail with + // "Source ServiceControl.Audit already exists". + EventSourceCreator.Create(); + + await WaitForSource(EventSourceCreator.SourceName); + } + + //There is a delay for this becoming true, tests will fall over if they interleave in the wrong way. + [SupportedOSPlatform("windows")] + static async Task WaitForSource(string sourceName) + { + var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60)); + while (!EventLog.SourceExists(sourceName)) + { + cts.Token.ThrowIfCancellationRequested(); + await Task.Delay(500, CancellationToken.None); + } + } +}