Ejemplo n.º 1
0
        private RemoteTestExecution StartTraceeProcess(string loggerCategory, string transportName = null)
        {
            _outputHelper.WriteLine("Starting tracee.");
            string exePath = CommonHelper.GetTraceePathWithArgs("EventPipeTracee", targetFramework: "net5.0");

            return(RemoteTestExecution.StartProcess(exePath + " " + loggerCategory, _outputHelper, transportName));
        }
Ejemplo n.º 2
0
 public static Task ExecutePipelineWithDebugee(
     ITestOutputHelper outputHelper,
     Pipeline pipeline,
     RemoteTestExecution testExecution,
     CancellationToken token,
     TaskCompletionSource <object> waitTaskSource = null)
 {
     return(ExecutePipelineWithDebugee(
                outputHelper,
                pipeline,
                (p, t) => Task.FromResult(p.RunAsync(t)),
                testExecution,
                token,
                waitTaskSource));
 }
Ejemplo n.º 3
0
        public static async Task ExecutePipelineWithDebugee(
            ITestOutputHelper outputHelper,
            Pipeline pipeline,
            RemoteTestExecution testExecution,
            TaskCompletionSource <object> waitTaskSource = null)
        {
            using var cancellation = new CancellationTokenSource(DefaultPipelineRunTimeout);

            await ExecutePipelineWithDebugee(
                outputHelper,
                pipeline,
                testExecution,
                cancellation.Token,
                waitTaskSource);
        }
Ejemplo n.º 4
0
        public static async Task ExecutePipelineWithDebugee <T>(
            ITestOutputHelper outputHelper,
            EventSourcePipeline <T> pipeline,
            RemoteTestExecution testExecution,
            TaskCompletionSource <object> waitTaskSource = null)
            where T : EventSourcePipelineSettings
        {
            using var cancellation = new CancellationTokenSource(DefaultPipelineRunTimeout);

            await ExecutePipelineWithDebugee(
                outputHelper,
                pipeline,
                (p, t) => p.StartAsync(t),
                testExecution,
                cancellation.Token,
                waitTaskSource);
        }
Ejemplo n.º 5
0
        private static async Task ExecutePipelineWithDebugee <TPipeline>(
            ITestOutputHelper outputHelper,
            TPipeline pipeline,
            Func <TPipeline, CancellationToken, Task <Task> > startPipelineAsync,
            RemoteTestExecution testExecution,
            CancellationToken token,
            TaskCompletionSource <object> waitTaskSource = null)
            where TPipeline : Pipeline
        {
            Task runTask = await startPipelineAsync(pipeline, token);

            //Begin event production
            testExecution.SendSignal();

            //Wait for event production to be done
            testExecution.WaitForSignal();

            try
            {
                // Optionally wait on caller before allowing the pipeline to stop.
                if (null != waitTaskSource)
                {
                    using var _ = token.Register(() =>
                    {
                        outputHelper.WriteLine("Did not receive completion signal before cancellation.");
                        waitTaskSource.TrySetCanceled(token);
                    });

                    await waitTaskSource.Task;
                }

                //Signal for the pipeline to stop
                await pipeline.StopAsync(token);

                //After a pipeline is stopped, we should expect the RunTask to eventually finish
                await runTask;
            }
            finally
            {
                //Signal for debugee that's ok to end/move on.
                testExecution.SendSignal();
            }
        }
        public static async Task ExecutePipelineWithDebugee(Pipeline pipeline, RemoteTestExecution testExecution)
        {
            Task processingTask = pipeline.RunAsync(CancellationToken.None);

            //Begin event production
            testExecution.SendSignal();

            //Wait for event production to be done
            testExecution.WaitForSignal();

            //Signal for the pipeline to stop
            await pipeline.StopAsync();

            //After a pipeline is stopped, we should expect the RunTask to eventually finish
            await processingTask;

            //Signal for debugee that's ok to end/move on.
            testExecution.SendSignal();
        }
Ejemplo n.º 7
0
 private RemoteTestExecution StartTraceeProcess(string loggerCategory)
 {
     return(RemoteTestExecution.StartProcess(CommonHelper.GetTraceePathWithArgs("EventPipeTracee") + " " + loggerCategory, _output));
 }
        public async Task ServerSourceAddRemoveMultipleConnectionTest()
        {
            await using var source = CreateServerSource(out string transportName);
            source.Start();

            var endpointInfos = await GetEndpointInfoAsync(source);

            Assert.Empty(endpointInfos);

            const int appCount = 5;

            RemoteTestExecution[] executions = new RemoteTestExecution[appCount];

            try
            {
                // Start all app instances
                for (int i = 0; i < appCount; i++)
                {
                    Task newEndpointInfoTask = source.WaitForNewEndpointInfoAsync(DefaultPositiveVerificationTimeout);

                    executions[i] = StartTraceeProcess("LoggerRemoteTest", transportName);

                    await newEndpointInfoTask;

                    executions[i].SendSignal();
                }

                await Task.Delay(TimeSpan.FromSeconds(1));

                endpointInfos = await GetEndpointInfoAsync(source);

                Assert.Equal(appCount, endpointInfos.Count());

                for (int i = 0; i < appCount; i++)
                {
                    IEndpointInfo endpointInfo = endpointInfos.FirstOrDefault(info => info.ProcessId == executions[i].TestRunner.Pid);
                    Assert.NotNull(endpointInfo);
                    Assert.NotNull(endpointInfo.CommandLine);
                    Assert.NotNull(endpointInfo.OperatingSystem);
                    Assert.NotNull(endpointInfo.ProcessArchitecture);

                    VerifyConnection(executions[i].TestRunner, endpointInfo);
                }
            }
            finally
            {
                _outputHelper.WriteLine("Stopping tracees.");

                int executionCount = 0;
                for (int i = 0; i < appCount; i++)
                {
                    if (null != executions[i])
                    {
                        executionCount++;
                        await executions[i].DisposeAsync();
                    }
                }
                Assert.Equal(appCount, executionCount);
            }

            await Task.Delay(TimeSpan.FromSeconds(1));

            endpointInfos = await GetEndpointInfoAsync(source);

            Assert.Empty(endpointInfos);
        }
        public static async Task ExecutePipelineWithDebugee(ITestOutputHelper outputHelper, Pipeline pipeline, RemoteTestExecution testExecution, CancellationToken token, TaskCompletionSource <object> waitTaskSource = null)
        {
            Task processingTask = pipeline.RunAsync(token);

            // Wait for event session to be established before telling target app to produce events.
            if (pipeline is IEventSourcePipelineInternal eventSourcePipeline)
            {
                await eventSourcePipeline.SessionStarted;
            }

            //Begin event production
            testExecution.SendSignal();

            //Wait for event production to be done
            testExecution.WaitForSignal();

            try
            {
                // Optionally wait on caller before allowing the pipeline to stop.
                if (null != waitTaskSource)
                {
                    using var _ = token.Register(() =>
                    {
                        outputHelper.WriteLine("Did not receive completion signal before cancellation.");
                        waitTaskSource.TrySetCanceled(token);
                    });

                    await waitTaskSource.Task;
                }

                //Signal for the pipeline to stop
                await pipeline.StopAsync(token);

                //After a pipeline is stopped, we should expect the RunTask to eventually finish
                await processingTask;
            }
            finally
            {
                //Signal for debugee that's ok to end/move on.
                testExecution.SendSignal();
            }
        }