How to use OptimizedRemoteMessageSink method of Xunit.Runner.v2.OptimizedRemoteMessageSink class

Best Xunit code snippet using Xunit.Runner.v2.OptimizedRemoteMessageSink.OptimizedRemoteMessageSink

Xunit2.cs

Source:Xunit2.cs Github

copy

Full Screen

...150 /// which can be passed to <see cref="ITestFrameworkDiscoverer"/> and <see cref="ITestFrameworkExecutor"/>.151 /// </summary>152 /// <param name="sink">The local message sink to receive the messages.</param>153 /// <param name="serializeDiscoveredTestCases">A flag which indicates whether test case serialization is required</param>154 protected IMessageSink CreateOptimizedRemoteMessageSink(155 _IMessageSink sink,156 bool serializeDiscoveredTestCases = true)157 {158 Guard.ArgumentNotNull(sink);159 var v2MessageSink = new Xunit2MessageSink(sink, TestAssemblyUniqueID, serializeDiscoveredTestCases ? remoteDiscoverer : null);160 try161 {162 var asssemblyName = typeof(OptimizedRemoteMessageSink).Assembly.GetName();163 var optimizedSink = AppDomain.CreateObject<IMessageSink>(asssemblyName, typeof(OptimizedRemoteMessageSink).FullName!, v2MessageSink);164 if (optimizedSink != null)165 return optimizedSink;166 }167 catch { } // This really shouldn't happen, but falling back makes sense in catastrophic cases168 return v2MessageSink;169 }170 /// <inheritdoc/>171 public virtual ValueTask DisposeAsync()172 {173 if (disposed)174 throw new ObjectDisposedException(GetType().FullName);175 disposed = true;176 return DisposalTracker.DisposeAsync();177 }178 /// <inheritdoc/>179 public void Find(180 _IMessageSink messageSink,181 FrontControllerFindSettings settings)182 {183 Guard.ArgumentNotNull(messageSink);184 Guard.ArgumentNotNull(settings);185 var includeSourceInformation = settings.Options.GetIncludeSourceInformationOrDefault();186 var filteringMessageSink = new FilteringMessageSink(messageSink, settings.Filters.Filter);187 // TODO: We're missing a potential optimization where we could determine that the filter188 // is exactly 1 (or maybe only?) "include class" filters, and then call the version of189 // Find on the remote discoverer that takes a type name.190 SendDiscoveryStartingMessage(messageSink);191 remoteDiscoverer.Find(192 includeSourceInformation,193 CreateOptimizedRemoteMessageSink(filteringMessageSink),194 Xunit2OptionsAdapter.Adapt(settings.Options)195 );196 }197 /// <inheritdoc/>198 public void FindAndRun(199 _IMessageSink messageSink,200 FrontControllerFindAndRunSettings settings)201 {202 Guard.NotNull($"This instance of {typeof(Xunit2).FullName} was created for discovery only; execution-related operations cannot be performed.", remoteExecutor);203 Guard.ArgumentNotNull(messageSink);204 Guard.ArgumentNotNull(settings);205 if (settings.Filters.Empty)206 {207 remoteExecutor.RunAll(208 CreateOptimizedRemoteMessageSink(messageSink),209 Xunit2OptionsAdapter.Adapt(settings.DiscoveryOptions),210 Xunit2OptionsAdapter.Adapt(settings.ExecutionOptions)211 );212 return;213 }214 using var discoverySink = new Xunit2DiscoverySink(settings.Filters);215 remoteDiscoverer.Find(216 includeSourceInformation: false,217 discoverySink,218 Xunit2OptionsAdapter.Adapt(settings.DiscoveryOptions)219 );220 discoverySink.Finished.WaitOne();221 remoteExecutor.RunTests(222 discoverySink.TestCases,223 CreateOptimizedRemoteMessageSink(messageSink),224 Xunit2OptionsAdapter.Adapt(settings.ExecutionOptions)225 );226 }227 static string GetExecutionAssemblyFileName(AppDomainSupport appDomainSupport, string basePath)228 {229 var supportedPlatformSuffixes = GetSupportedPlatformSuffixes(appDomainSupport);230 foreach (var suffix in supportedPlatformSuffixes)231 {232#if NETFRAMEWORK233 var fileName = Path.Combine(basePath, $"xunit.execution.{suffix}.dll");234 if (File.Exists(fileName))235 return fileName;236#else237 try238 {239 var assemblyName = $"xunit.execution.{suffix}";240 Assembly.Load(new AssemblyName { Name = assemblyName });241 return assemblyName + ".dll";242 }243 catch { }244#endif245 }246 throw new InvalidOperationException("Could not find/load any of the following assemblies: " + string.Join(", ", supportedPlatformSuffixes.Select(suffix => $"xunit.execution.{suffix}.dll").ToArray()));247 }248 static string[] GetSupportedPlatformSuffixes(AppDomainSupport appDomainSupport)249 {250#if NETFRAMEWORK251 return appDomainSupport == AppDomainSupport.Required ? SupportedPlatforms_ForcedAppDomains : SupportedPlatforms;252#else253 return SupportedPlatforms;254#endif255 }256 static AssemblyName GetTestFrameworkAssemblyName(string xunitExecutionAssemblyPath)257 {258#if NETFRAMEWORK259 return AssemblyName.GetAssemblyName(xunitExecutionAssemblyPath);260#else261 // Make sure we only use the short form262 return Assembly.Load(new AssemblyName { Name = Path.GetFileNameWithoutExtension(xunitExecutionAssemblyPath), Version = new Version(0, 0, 0, 0) }).GetName();263#endif264 }265 static string GetXunitExecutionAssemblyPath(266 AppDomainSupport appDomainSupport,267 string assemblyFileName,268 bool verifyTestAssemblyExists)269 {270 Guard.ArgumentNotNullOrEmpty(assemblyFileName);271 if (verifyTestAssemblyExists)272 Guard.FileExists(assemblyFileName);273 return GetExecutionAssemblyFileName(appDomainSupport, Path.GetDirectoryName(assemblyFileName)!);274 }275 static string GetXunitExecutionAssemblyPath(276 AppDomainSupport appDomainSupport,277 _IAssemblyInfo assemblyInfo)278 {279 Guard.ArgumentNotNull(assemblyInfo);280 Guard.ArgumentNotNullOrEmpty(assemblyInfo.AssemblyPath);281 return GetExecutionAssemblyFileName(appDomainSupport, Path.GetDirectoryName(assemblyInfo.AssemblyPath)!);282 }283#if NETFRAMEWORK284 static bool IsDotNet(string executionAssemblyFileName) =>285 executionAssemblyFileName.EndsWith(".dotnet.dll", StringComparison.Ordinal);286#endif287 /// <inheritdoc/>288 public void Run(289 _IMessageSink messageSink,290 FrontControllerRunSettings settings)291 {292 Guard.NotNull($"This instance of {typeof(Xunit2).FullName} was created for discovery only; execution-related operations cannot be performed.", remoteExecutor);293 Guard.ArgumentNotNull(messageSink);294 Guard.ArgumentNotNull(settings);295 remoteExecutor.RunTests(296 BulkDeserialize(settings.SerializedTestCases.ToList()).Select(kvp => kvp.Value).ToList(),297 CreateOptimizedRemoteMessageSink(messageSink),298 Xunit2OptionsAdapter.Adapt(settings.Options)299 );300 }301 void SendDiscoveryStartingMessage(_IMessageSink messageSink)302 {303 // There is no v2 equivalent to this, so we manufacture it ourselves304 var discoveryStarting = new _DiscoveryStarting305 {306 AssemblyName = assemblyInfo.Name,307 AssemblyPath = assemblyInfo.AssemblyPath,308 AssemblyUniqueID = UniqueIDGenerator.ForAssembly(assemblyInfo.Name, assemblyInfo.AssemblyPath, configFileName),309 ConfigFilePath = configFileName310 };311 messageSink.OnMessage(discoveryStarting);...

Full Screen

Full Screen

Xunit2Discoverer.cs

Source:Xunit2Discoverer.cs Github

copy

Full Screen

...139 /// Creates a high performance cross AppDomain message sink that utilizes <see cref="IMessageSinkWithTypes"/>140 /// which can be passed to <see cref="ITestFrameworkDiscoverer"/> and <see cref="ITestFrameworkExecutor"/>.141 /// </summary>142 /// <param name="sink">The local message sink to receive the messages.</param>143 protected IMessageSink CreateOptimizedRemoteMessageSink(IMessageSink sink)144 {145 Guard.ArgumentNotNull(nameof(sink), sink);146 try147 {148 var sinkWithTypes = MessageSinkWithTypesAdapter.Wrap(sink);149 var asssemblyName = typeof(OptimizedRemoteMessageSink).Assembly.GetName();150 var optimizedSink = AppDomain.CreateObject<IMessageSink>(asssemblyName, typeof(OptimizedRemoteMessageSink).FullName!, sinkWithTypes);151 if (optimizedSink != null)152 return optimizedSink;153 }154 catch { } // This really shouldn't happen, but falling back makes sense in catastrophic cases155 return sink;156 }157 /// <inheritdoc/>158 public virtual void Dispose()159 {160 RemoteDiscoverer?.Dispose();161 Framework?.Dispose();162#if NETFRAMEWORK163 assemblyHelper?.Dispose();164#endif165 AppDomain?.Dispose();166 }167 /// <summary>168 /// Starts the process of finding all xUnit.net v2 tests in an assembly.169 /// </summary>170 /// <param name="includeSourceInformation">Whether to include source file information, if possible.</param>171 /// <param name="messageSink">The message sink to report results back to.</param>172 /// <param name="discoveryOptions">The options used by the test framework during discovery.</param>173 public void Find(bool includeSourceInformation, IMessageSink messageSink, ITestFrameworkDiscoveryOptions discoveryOptions)174 {175 Guard.ArgumentNotNull(nameof(messageSink), messageSink);176 Guard.ArgumentNotNull(nameof(discoveryOptions), discoveryOptions);177 RemoteDiscoverer.Find(includeSourceInformation, CreateOptimizedRemoteMessageSink(messageSink), discoveryOptions);178 }179 /// <summary>180 /// Starts the process of finding all xUnit.net v2 tests in a class.181 /// </summary>182 /// <param name="typeName">The fully qualified type name to find tests in.</param>183 /// <param name="includeSourceInformation">Whether to include source file information, if possible.</param>184 /// <param name="messageSink">The message sink to report results back to.</param>185 /// <param name="discoveryOptions">The options used by the test framework during discovery.</param>186 public void Find(string typeName, bool includeSourceInformation, IMessageSink messageSink, ITestFrameworkDiscoveryOptions discoveryOptions)187 {188 Guard.ArgumentNotNull(nameof(messageSink), messageSink);189 Guard.ArgumentNotNull(nameof(discoveryOptions), discoveryOptions);190 RemoteDiscoverer.Find(typeName, includeSourceInformation, CreateOptimizedRemoteMessageSink(messageSink), discoveryOptions);191 }192 /// <inheritdoc/>193 public List<TestCaseDescriptor> GetTestCaseDescriptors(List<ITestCase> testCases, bool includeSerialization)194 {195 Guard.ArgumentNotNull(nameof(testCases), testCases);196 var callbackContainer = new DescriptorCallback();197 Action<List<string>> callback = callbackContainer.Callback;198 if (defaultTestCaseDescriptorProvider == null)199 {200 if (AppDomain.HasAppDomain)201 {202 try203 {204 AppDomain.CreateObject<object>(TestFrameworkAssemblyName, "Xunit.Sdk.TestCaseDescriptorFactory", includeSerialization ? RemoteDiscoverer : null, testCases, callback);...

Full Screen

Full Screen

OptimizedRemoteMessageSink.cs

Source:OptimizedRemoteMessageSink.cs Github

copy

Full Screen

...10 /// This class exists to live inside the v2 remote AppDomain and provide an optimized message11 /// sink which calls through to a runner-side implementation of <see cref="IMessageSinkMessageWithTypes"/>.12 /// This allows higher performance type dispatching, since retrieving and passing along the remote-side13 /// interface list is much faster than attempting to do cross-AppDomain casts. This class is created14 /// remotely in <see cref="Xunit2.CreateOptimizedRemoteMessageSink"/>.15 /// </summary>16 class OptimizedRemoteMessageSink : LongLivedMarshalByRefObject, IMessageSink17 {18 readonly ReaderWriterLockSlim cacheLock = new();19 readonly Dictionary<Type, HashSet<string>> interfaceCache = new();20 readonly IMessageSinkWithTypes runnerSink;21 public OptimizedRemoteMessageSink(IMessageSinkWithTypes runnerSink)22 {23 Guard.ArgumentNotNull(runnerSink);24 this.runnerSink = runnerSink;25 }26 HashSet<string> GetMessageTypes(IMessageSinkMessage message)27 {28 var messageType = message.GetType();29 HashSet<string>? result;30 cacheLock.TryEnterReadLock(-1);31 try32 {33 interfaceCache.TryGetValue(messageType, out result);34 }35 finally...

Full Screen

Full Screen

OptimizedRemoteMessageSink

Using AI Code Generation

copy

Full Screen

1using System;2using Xunit.Runner.v2;3using Xunit.Runner.v2.Remoting;4using Xunit.Runner.v2.Remoting.Execution;5using Xunit.Runner.v2.Remoting.Execution.Messages;6{7 public static void Main()8 {9 var remoteSink = new OptimizedRemoteMessageSink();10 var remoteSinkMethod = remoteSink.GetType().GetMethod("OptimizedRemoteMessageSink");11 var remoteSinkDelegate = remoteSinkMethod.CreateDelegate(typeof(Action<IRemotingMessage>));12 var remoteSinkDelegateCast = (Action<IRemotingMessage>)remoteSinkDelegate;13 var remoteSinkDelegateCastInvoke = remoteSinkDelegateCast.Invoke(new TestMessage());14 }15}16using System;17using Xunit.Runner.v2;18using Xunit.Runner.v2.Remoting;19using Xunit.Runner.v2.Remoting.Execution;20using Xunit.Runner.v2.Remoting.Execution.Messages;21{22 public static void Main()23 {24 var remoteSink = new OptimizedRemoteMessageSink();25 var remoteSinkMethod = remoteSink.GetType().GetMethod("OptimizedRemoteMessageSink");26 var remoteSinkDelegate = remoteSinkMethod.CreateDelegate(typeof(Action<IRemotingMessage>));27 var remoteSinkDelegateCast = (Action<IRemotingMessage>)remoteSinkDelegate;28 var remoteSinkDelegateCastInvoke = remoteSinkDelegateCast.Invoke(new TestMessage());29 }30}31using System;32using Xunit.Runner.v2;33using Xunit.Runner.v2.Remoting;34using Xunit.Runner.v2.Remoting.Execution;35using Xunit.Runner.v2.Remoting.Execution.Messages;36{37 public static void Main()38 {39 var remoteSink = new OptimizedRemoteMessageSink();40 var remoteSinkMethod = remoteSink.GetType().GetMethod("OptimizedRemoteMessageSink");41 var remoteSinkDelegate = remoteSinkMethod.CreateDelegate(typeof(Action<IRemotingMessage>));42 var remoteSinkDelegateCast = (Action<IRemoting

Full Screen

Full Screen

OptimizedRemoteMessageSink

Using AI Code Generation

copy

Full Screen

1using Xunit.Abstractions;2using Xunit.Runner.v2;3{4 {5 public void Test()6 {

Full Screen

Full Screen

OptimizedRemoteMessageSink

Using AI Code Generation

copy

Full Screen

1using Xunit.Runner.v2;2using Xunit.Runner.v2;3using Xunit.Runner.v2;4using Xunit.Runner.v2;5{6 {7 private readonly IRunnerLogger _innerSink;8 public OptimizedRemoteMessageSink(IRunnerLogger innerSink)9 {10 _innerSink = innerSink;11 }12 public void AssemblyFinished(AssemblyFinishedInfo assemblyFinishedInfo)13 {14 _innerSink.AssemblyFinished(assemblyFinishedInfo);15 }16 public void AssemblyStarting(AssemblyStartingInfo assemblyStartingInfo)17 {18 _innerSink.AssemblyStarting(assemblyStartingInfo);19 }20 public void TestAssemblyCleanupFailure(TestAssemblyCleanupFailureInfo testAssemblyCleanupFailureInfo)21 {22 _innerSink.TestAssemblyCleanupFailure(testAssemblyCleanupFailureInfo);23 }24 public void TestAssemblyFinished(TestAssemblyFinishedInfo testAssemblyFinishedInfo)25 {26 _innerSink.TestAssemblyFinished(testAssemblyFinishedInfo);27 }28 public void TestAssemblyStarting(TestAssemblyStartingInfo testAssemblyStartingInfo)29 {30 _innerSink.TestAssemblyStarting(testAssemblyStartingInfo);31 }32 public void TestCaseCleanupFailure(TestCaseCleanupFailureInfo testCaseCleanupFailureInfo)33 {34 _innerSink.TestCaseCleanupFailure(testCaseCleanupFailureInfo);35 }36 public void TestCaseFinished(TestCaseFinishedInfo testCaseFinishedInfo)37 {38 _innerSink.TestCaseFinished(testCaseFinishedInfo);39 }40 public void TestCaseStarting(TestCaseStartingInfo testCaseStartingInfo)41 {42 _innerSink.TestCaseStarting(testCaseStartingInfo);43 }44 public void TestClassCleanupFailure(TestClassCleanupFailureInfo testClassCleanupFailureInfo)45 {46 _innerSink.TestClassCleanupFailure(testClassCleanupFailureInfo);47 }48 public void TestClassConstructionFinished(TestClassConstructionFinishedInfo testClassConstructionFinishedInfo)49 {50 _innerSink.TestClassConstructionFinished(testClassConstructionFinishedInfo);51 }52 public void TestClassConstructionStarting(TestClassConstructionStartingInfo testClassConstructionStartingInfo)53 {54 _innerSink.TestClassConstructionStarting(testClassConstructionStartingInfo);55 }56 public void TestClassDisposeFinished(TestClassDisposeFinishedInfo testClassDisposeFinishedInfo)57 {58 _innerSink.TestClassDisposeFinished(testClassDisposeFinishedInfo);59 }60 public void TestClassDisposeStarting(TestClassDisposeStartingInfo testClassDisposeStartingInfo)61 {

Full Screen

Full Screen

OptimizedRemoteMessageSink

Using AI Code Generation

copy

Full Screen

1using System;2using Xunit.Abstractions;3using Xunit.Runner.v2;4{5 {6 private readonly OptimizedRemoteMessageSink _sink;7 public OptimizedRemoteMessageSink(OptimizedRemoteMessageSink sink)8 {9 _sink = sink;10 }11 public bool OnMessage(IMessageSinkMessage message)12 {13 if (message is TestAssemblyFinished assemblyFinished)14 {15 _sink.SendMessage(new OptimizedRemoteMessageSinkMessage16 {17 });18 }19 else if (message is TestAssemblyStarting assemblyStarting)20 {21 _sink.SendMessage(new OptimizedRemoteMessageSinkMessage22 {23 });24 }25 else if (message is TestAssemblyCleanupFailure cleanupFailure)26 {27 _sink.SendMessage(new OptimizedRemoteMessageSinkMessage28 {29 });30 }31 else if (message is TestAssemblyCleanupFailureCleanupFailure)32 {33 _sink.SendMessage(new OptimizedRemoteMessageSinkMessage34 {

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Xunit automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in OptimizedRemoteMessageSink

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful