How to use Dispose method of Xunit.Runner.Common.AppVeyorClient class

Best Xunit code snippet using Xunit.Runner.Common.AppVeyorClient.Dispose

ApplicationInsightsEndToEndTests.cs

Source:ApplicationInsightsEndToEndTests.cs Github

copy

Full Screen

...279 keepRunning = false;280 await functionTask;281 await host.StopAsync();282 listener.StopListening();283 listener.Dispose();284 }285 string GetFailureString()286 {287 return string.Join(Environment.NewLine, _channel.Telemetries.OrderBy(p => p.Timestamp).Select(t =>288 {289 string timestamp = $"[{t.Timestamp.ToString(_dateFormat)}] ";290 switch (t)291 {292 case DependencyTelemetry dependency:293 return timestamp + $"[Dependency] {dependency.Name}; {dependency.Target}; {dependency.Data}";294 case TraceTelemetry trace:295 return timestamp + $"[Trace] {trace.Message}";296 case RequestTelemetry request:297 return timestamp + $"[Request] {request.Name}: {request.Success}";298 default:299 return timestamp + $"[{t.GetType().Name}]";300 }301 }));302 }303 int expectedTelemetryItems = additionalTraces + (functionsCalled * tracesPerRequest);304 // Filter out the odd auto-tracked request that we occassionally see from AppVeyor. 305 // From here: https://github.com/xunit/xunit/blob/9d10262a3694bb099ddd783d735aba2a7aac759d/src/xunit.runner.reporters/AppVeyorClient.cs#L21306 var actualTelemetries = _channel.Telemetries307 .Where(p => !(p is DependencyTelemetry d && d.Name == "POST /api/tests/batch"))308 .ToArray();309 Assert.True(actualTelemetries.Length == expectedTelemetryItems,310 $"Expected: {expectedTelemetryItems}; Actual: {actualTelemetries.Length}{Environment.NewLine}{GetFailureString()}");311 }312 }313 [Fact]314 public async Task ApplicationInsights_AIUsedExplicitlyFromFunctionCode()315 {316 string testName = nameof(TestApplicationInsightsExplicitCall);317 using (IHost host = ConfigureHost())318 {319 await host.StartAsync();320 MethodInfo methodInfo = GetType().GetMethod(testName, BindingFlags.Public | BindingFlags.Static);321 await host.GetJobHost().CallAsync(methodInfo, null);322 await host.StopAsync();323 EventTelemetry[] eventTelemetries = _channel.Telemetries.OfType<EventTelemetry>().ToArray();324 Assert.Single(eventTelemetries);325 RequestTelemetry requestTelemetry = _channel.Telemetries.OfType<RequestTelemetry>().Single();326 Assert.Equal(requestTelemetry.Context.Operation.Name, eventTelemetries[0].Context.Operation.Name);327 Assert.Equal(requestTelemetry.Context.Operation.Id, eventTelemetries[0].Context.Operation.Id);328 Assert.Equal(requestTelemetry.Id, eventTelemetries[0].Context.Operation.ParentId);329 }330 }331 [Theory]332 [InlineData(true, true)]333 [InlineData(true, false)]334 [InlineData(false, true)]335 [InlineData(false, false)]336 public async Task ApplicationInsights_CustomStartOperation(bool testRequestTelemetry, bool useCustomOperationId)337 {338 string testName = nameof(TestApplicationInsightsStartOperation);339 using (IHost host = ConfigureHost())340 {341 var telemetryClient = host.Services.GetRequiredService<TelemetryClient>();342 string customOperationId = useCustomOperationId ? ActivityTraceId.CreateRandom().ToHexString() : null;343 await host.StartAsync();344 MethodInfo methodInfo = GetType().GetMethod(testName, BindingFlags.Public | BindingFlags.Static);345 await host.GetJobHost().CallAsync(methodInfo, new {346 telemetryClient = telemetryClient,347 testRequestTelemetry = testRequestTelemetry,348 customOperationId = customOperationId349 });350 await host.StopAsync();351 OperationTelemetry[] telemetries = _channel.Telemetries.OfType<OperationTelemetry>().ToArray();352 Assert.Equal(2, telemetries.Length);353 Assert.Single(telemetries.Where(t => t.Name == "custom"));354 if (useCustomOperationId)355 {356 Assert.Equal(customOperationId, telemetries.Single(t => t.Name == "custom").Context.Operation.Id);357 }358 else359 {360 Assert.Equal(telemetries[0].Context.Operation.Id, telemetries[1].Context.Operation.Id);361 }362 }363 }364 [Fact]365 public async Task ApplicationInsights_OuterRequestIsTrackedOnce()366 {367 string testName = nameof(TestApplicationInsightsInformation);368 using (IHost host = ConfigureHost())369 {370 TelemetryClient telemetryClient = host.Services.GetService<TelemetryClient>();371 await host.StartAsync();372 MethodInfo methodInfo = GetType().GetMethod(testName, BindingFlags.Public | BindingFlags.Static);373 RequestTelemetry outerRequest = null;374 // simulate auto tracked HTTP incoming call375 using (IOperationHolder<RequestTelemetry> operation = telemetryClient.StartOperation<RequestTelemetry>("request name"))376 {377 outerRequest = operation.Telemetry;378 outerRequest.Url = new Uri("http://my-func/api/func-name?name=123");379 outerRequest.Success = true;380 await host.GetJobHost().CallAsync(methodInfo, new { input = "input" });381 }382 await host.StopAsync();383 // Validate the request384 // There must be only one reported by the AppInsights request collector385 RequestTelemetry[] requestTelemetries = _channel.Telemetries.OfType<RequestTelemetry>().ToArray();386 Assert.Single(requestTelemetries);387 RequestTelemetry functionRequest = requestTelemetries.Single();388 Assert.Same(outerRequest, functionRequest);389 Assert.True(double.TryParse(functionRequest.Properties[LogConstants.FunctionExecutionTimeKey], out double functionDuration));390 Assert.True(functionRequest.Duration.TotalMilliseconds >= functionDuration);391 Assert.Equal("0.0.0.0", functionRequest.Context.Location.Ip);392 ValidateRequest(functionRequest, testName, testName, "GET", "/api/func-name", true, "0");393 }394 }395 [Theory]396 [InlineData(nameof(TestApplicationInsightsInformation), true)]397 [InlineData(nameof(TestApplicationInsightsFailure), false)]398 public async Task ApplicationInsights_HttpRequestTrackingByWebJobs(string testName, bool success)399 {400 var client = _factory.CreateClient();401 var httpOptions = new HttpAutoCollectionOptions402 {403 EnableHttpTriggerExtendedInfoCollection = false404 };405 using (IHost host = ConfigureHost(httpOptions: httpOptions))406 {407 Startup.Host = host;408 await host.StartAsync();409 var loggerProvider = host.Services.GetServices<ILoggerProvider>().OfType<ApplicationInsightsLoggerProvider>().Single();410 var logger = loggerProvider.CreateLogger(LogCategories.Results);411 var request = new HttpRequestMessage(HttpMethod.Get, $"/some/path?name={testName}");412 request.Headers.Add("traceparent", "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01");413 var mockHttpContext = new DefaultHttpContext();414 mockHttpContext.Connection.RemoteIpAddress = new IPAddress(new byte[] { 1, 2, 3, 4 });415 // simulate functions behavior to set request on the scope416 using (var _ = logger.BeginScope(new Dictionary<string, object> { ["MS_HttpRequest"] = mockHttpContext.Request }))417 {418 await client.SendAsync(request);419 }420 await host.StopAsync();421 // Validate the request422 // There must be only one reported by the AppInsights request collector423 // The telemetry may come back slightly later, so wait until we see it424 RequestTelemetry functionRequest = null;425 await TestHelpers.Await(() =>426 {427 functionRequest = _channel.Telemetries.OfType<RequestTelemetry>().SingleOrDefault();428 return functionRequest != null;429 });430 Assert.True(double.TryParse(functionRequest.Properties[LogConstants.FunctionExecutionTimeKey], out double functionDuration));431 Assert.True(functionRequest.Duration.TotalMilliseconds >= functionDuration);432 Assert.Equal("1.2.3.4", functionRequest.Context.Location.Ip);433 Assert.Null(functionRequest.Url);434 ValidateRequest(435 functionRequest,436 testName,437 testName,438 null,439 null,440 success);441 // Make sure operation ids match442 var traces = _channel.Telemetries.OfType<TraceTelemetry>()443 .Where(t => t.Context.Operation.Id == functionRequest.Context.Operation.Id);444 Assert.Equal(success ? 4 : 5, traces.Count());445 }446 }447 [Fact]448 public async Task ApplicationInsights_EventHubTrackingByWebJobs_SingleLink_LegacyCompatibleFormat()449 {450 string testName = nameof(TestApplicationInsightsInformation);451 using (IHost host = ConfigureHost())452 {453 Startup.Host = host;454 await host.StartAsync();455 var loggerProvider = host.Services.GetServices<ILoggerProvider>().OfType<ApplicationInsightsLoggerProvider>().Single();456 var logger = loggerProvider.CreateLogger(LogCategories.Results);457 string operationId = ActivityTraceId.CreateRandom().ToHexString();458 string parentId = $"|{operationId}.{ActivitySpanId.CreateRandom().ToHexString()}.";459 // simulate functions behavior to set request on the scope460 using (var _ = logger.BeginScope(new Dictionary<string, object>461 {462 ["Links"] = new[] { new Activity("event hub process").SetParentId(parentId) }463 }))464 {465 MethodInfo methodInfo = GetType().GetMethod(testName, BindingFlags.Public | BindingFlags.Static);466 await host.GetJobHost().CallAsync(methodInfo, new { input = "function input" });467 }468 await host.StopAsync();469 // Validate the request470 RequestTelemetry functionRequest = _channel.Telemetries.OfType<RequestTelemetry>().SingleOrDefault();471 ValidateRequest(472 functionRequest,473 testName,474 testName,475 null,476 null,477 true,478 "0",479 operationId,480 parentId);481 // Make sure operation ids match482 var traces = _channel.Telemetries.OfType<TraceTelemetry>().Where(t => t.Context.Operation.Id == functionRequest.Context.Operation.Id);483 Assert.Equal(4, traces.Count());484 Assert.False(functionRequest.Properties.ContainsKey("_MS.links"));485 Assert.False(functionRequest.Properties.ContainsKey("Links"));486 }487 }488 [Fact]489 public async Task ApplicationInsights_EventHubTrackingByWebJobs_SingleLink_LegacyIncompatibleFormat()490 {491 string testName = nameof(TestApplicationInsightsInformation);492 using (IHost host = ConfigureHost())493 {494 Startup.Host = host;495 await host.StartAsync();496 var loggerProvider = host.Services.GetServices<ILoggerProvider>().OfType<ApplicationInsightsLoggerProvider>().Single();497 var logger = loggerProvider.CreateLogger(LogCategories.Results);498 string parentId = "|legacyRoot.1.2.3.";499 // simulate functions behavior to set request on the scope500 using (var _ = logger.BeginScope(new Dictionary<string, object>501 {502 ["Links"] = new[] { new Activity("event hub process").SetParentId(parentId) }503 }))504 {505 MethodInfo methodInfo = GetType().GetMethod(testName, BindingFlags.Public | BindingFlags.Static);506 await host.GetJobHost().CallAsync(methodInfo, new { input = "function input" });507 }508 await host.StopAsync();509 // Validate the request510 RequestTelemetry functionRequest = _channel.Telemetries.OfType<RequestTelemetry>().SingleOrDefault();511 ValidateRequest(512 functionRequest,513 testName,514 testName,515 null,516 null,517 true,518 "0",519 null,520 parentId);521 // Make sure operation ids match522 var traces = _channel.Telemetries.OfType<TraceTelemetry>().Where(523 t => t.Context.Operation.Id == functionRequest.Context.Operation.Id);524 Assert.Equal(4, traces.Count());525 Assert.False(functionRequest.Properties.ContainsKey("_MS.links"));526 Assert.True(functionRequest.Properties.TryGetValue("ai_legacyRootId", out var legacyRoot));527 Assert.Equal("legacyRoot", legacyRoot);528 Assert.False(functionRequest.Properties.ContainsKey("Links"));529 }530 }531 [Theory]532 [InlineData(true)]533 [InlineData(false)]534 public async Task ApplicationInsights_EventHubTrackingByWebJobs_SingleLink(bool sampledIn)535 {536 string testName = nameof(TestApplicationInsightsInformation);537 using (IHost host = ConfigureHost())538 {539 Startup.Host = host;540 await host.StartAsync();541 var loggerProvider = host.Services.GetServices<ILoggerProvider>().OfType<ApplicationInsightsLoggerProvider>().Single();542 var logger = loggerProvider.CreateLogger(LogCategories.Results);543 string traceId = ActivityTraceId.CreateRandom().ToHexString();544 string parentSpanId = ActivitySpanId.CreateRandom().ToHexString();545 string traceFlags = sampledIn ? "01" : "00";546 string parentId = $"00-{traceId}-{parentSpanId}-{traceFlags}";547 var linkEnqueuedTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();548 var link = new Activity("event hub process").SetParentId(parentId);549 link.AddTag(LogConstants.MessageEnqueuedTimeKey, linkEnqueuedTime.ToString());550 // simulate functions behavior to set request on the scope551 using (var _ = logger.BeginScope(new Dictionary<string, object> { ["Links"] = new[] { link }, }))552 {553 MethodInfo methodInfo = GetType().GetMethod(testName, BindingFlags.Public | BindingFlags.Static);554 await host.GetJobHost().CallAsync(methodInfo, new { input = "function input" });555 }556 await host.StopAsync();557 // Validate the request558 RequestTelemetry functionRequest = _channel.Telemetries.OfType<RequestTelemetry>().SingleOrDefault();559 ValidateRequest(560 functionRequest,561 testName,562 testName,563 null,564 null,565 true,566 "0",567 traceId,568 parentSpanId);569 Assert.Equal(sampledIn ? SamplingDecision.SampledIn : SamplingDecision.None, functionRequest.ProactiveSamplingDecision); 570 // Make sure operation ids match571 var traces = _channel.Telemetries.OfType<TraceTelemetry>().Where(t => t.Context.Operation.Id == functionRequest.Context.Operation.Id);572 Assert.Equal(4, traces.Count());573 Assert.False(functionRequest.Properties.ContainsKey("_MS.links"));574 Assert.False(functionRequest.Properties.ContainsKey("Links"));575 Assert.True(functionRequest.Metrics.TryGetValue("timeSinceEnqueued", out var timeSinceEnqueued));576 Assert.Equal(functionRequest.Timestamp.ToUnixTimeMilliseconds() - linkEnqueuedTime, timeSinceEnqueued, 0);577 }578 }579 [Fact]580 public async Task ApplicationInsights_EventHubTrackingByWebJobs_SingleLink_NoTimeInQueue()581 {582 string testName = nameof(TestApplicationInsightsInformation);583 using (IHost host = ConfigureHost())584 {585 Startup.Host = host;586 await host.StartAsync();587 var loggerProvider = host.Services.GetServices<ILoggerProvider>().OfType<ApplicationInsightsLoggerProvider>().Single();588 var logger = loggerProvider.CreateLogger(LogCategories.Results);589 string traceId = ActivityTraceId.CreateRandom().ToHexString();590 string parentSpanId = ActivitySpanId.CreateRandom().ToHexString();591 string parentId = $"00-{traceId}-{parentSpanId}-01";592 var link = new Activity("event hub process").SetParentId(parentId);593 // simulate functions behavior to set request on the scope594 using (var _ = logger.BeginScope(new Dictionary<string, object> { ["Links"] = new[] { link } }))595 {596 MethodInfo methodInfo = GetType().GetMethod(testName, BindingFlags.Public | BindingFlags.Static);597 await host.GetJobHost().CallAsync(methodInfo, new { input = "function input" });598 }599 await host.StopAsync();600 RequestTelemetry functionRequest = _channel.Telemetries.OfType<RequestTelemetry>().SingleOrDefault();601 Assert.False(functionRequest.Metrics.ContainsKey("timeSinceEnqueued"));602 }603 }604 [Theory]605 [InlineData(true)]606 [InlineData(false)]607 public async Task ApplicationInsights_EventHubTrackingByWebJobs_MultipleLinks(bool anySampledIn)608 {609 string testName = nameof(TestApplicationInsightsInformation);610 using (IHost host = ConfigureHost())611 {612 Startup.Host = host;613 await host.StartAsync();614 var loggerProvider = host.Services.GetServices<ILoggerProvider>().OfType<ApplicationInsightsLoggerProvider>().Single();615 var logger = loggerProvider.CreateLogger(LogCategories.Results);616 var links = new Activity[2];617 links[0] = new Activity("link0").SetParentId(618 ActivityTraceId.CreateRandom(), 619 ActivitySpanId.CreateRandom(), 620 anySampledIn ? ActivityTraceFlags.Recorded : ActivityTraceFlags.None);621 var link0EnqueuedTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();622 links[0].AddTag(LogConstants.MessageEnqueuedTimeKey, link0EnqueuedTime.ToString());623 links[1] = new Activity("link1").SetParentId(624 ActivityTraceId.CreateRandom(), 625 ActivitySpanId.CreateRandom(),626 ActivityTraceFlags.None);627 var link1EnqueuedTime = DateTimeOffset.UtcNow.AddMilliseconds(-100).ToUnixTimeMilliseconds();628 links[1].AddTag(LogConstants.MessageEnqueuedTimeKey, link1EnqueuedTime.ToString());629 // simulate functions behavior to set request on the scope630 using (var _ = logger.BeginScope(new Dictionary<string, object>631 {632 ["Links"] = links633 }))634 {635 MethodInfo methodInfo = GetType().GetMethod(testName, BindingFlags.Public | BindingFlags.Static);636 await host.GetJobHost().CallAsync(methodInfo, new { input = "function input" });637 }638 await host.StopAsync();639 // Validate the request640 RequestTelemetry functionRequest = _channel.Telemetries.OfType<RequestTelemetry>().SingleOrDefault();641 ValidateRequest(642 functionRequest,643 testName,644 testName,645 null,646 null,647 true);648 // Make sure operation ids match649 var traces = _channel.Telemetries.OfType<TraceTelemetry>().Where(t => t.Context.Operation.Id == functionRequest.Context.Operation.Id).ToArray();650 Assert.Equal(4, traces.Length);651 foreach (var trace in traces)652 {653 Assert.Equal(anySampledIn ? SamplingDecision.SampledIn : SamplingDecision.None, trace.ProactiveSamplingDecision);654 }655 Assert.Equal(anySampledIn ? SamplingDecision.SampledIn : SamplingDecision.None,656 functionRequest.ProactiveSamplingDecision);657 Assert.False(functionRequest.Properties.ContainsKey("Links"));658 Assert.True(functionRequest.Properties.TryGetValue("_MS.links", out var linksStr));659 // does not throw660 var actualLinks = JsonConvert.DeserializeObject<TestLink[]>(linksStr, jsonSettingThrowOnError);661 Assert.NotNull(actualLinks);662 Assert.Equal(2, actualLinks.Length);663 var linkTraceId0 = links[0].TraceId.ToHexString();664 var linkTraceId1 = links[1].TraceId.ToHexString();665 Assert.Equal(linkTraceId0, actualLinks[0].operation_Id);666 Assert.Equal(linkTraceId1, actualLinks[1].operation_Id);667 var linkSpanId0 = links[0].ParentSpanId.ToHexString();668 var linkSpanId1 = links[1].ParentSpanId.ToHexString();669 Assert.Equal(linkSpanId0, actualLinks[0].id);670 Assert.Equal(linkSpanId1, actualLinks[1].id);671 Assert.Equal($"[{{\"operation_Id\":\"{linkTraceId0}\",\"id\":\"{linkSpanId0}\"}},{{\"operation_Id\":\"{linkTraceId1}\",\"id\":\"{linkSpanId1}\"}}]", linksStr);672 Assert.True(functionRequest.Metrics.TryGetValue("timeSinceEnqueued", out var timeSinceEnqueued));673 var expectedTimeInQueue = ((functionRequest.Timestamp.ToUnixTimeMilliseconds() - link0EnqueuedTime) +674 (functionRequest.Timestamp.ToUnixTimeMilliseconds() - link1EnqueuedTime)) / 2;675 Assert.Equal(expectedTimeInQueue, timeSinceEnqueued, 0);676 }677 }678 [Fact]679 public async Task ApplicationInsights_EventHubTrackingByWebJobs_MultipleLinks_NegativeTimeInQueue()680 {681 string testName = nameof(TestApplicationInsightsInformation);682 using (IHost host = ConfigureHost())683 {684 Startup.Host = host;685 await host.StartAsync();686 var loggerProvider = host.Services.GetServices<ILoggerProvider>().OfType<ApplicationInsightsLoggerProvider>().Single();687 var logger = loggerProvider.CreateLogger(LogCategories.Results);688 var links = new Activity[2];689 links[0] = new Activity("link0").SetParentId(690 ActivityTraceId.CreateRandom(),691 ActivitySpanId.CreateRandom(),692 ActivityTraceFlags.Recorded);693 var link0EnqueuedTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();694 links[0].AddTag(LogConstants.MessageEnqueuedTimeKey, link0EnqueuedTime.ToString());695 links[1] = new Activity("link1").SetParentId(696 ActivityTraceId.CreateRandom(),697 ActivitySpanId.CreateRandom());698 var link1EnqueuedTime = DateTimeOffset.UtcNow.AddMilliseconds(1000).ToUnixTimeMilliseconds();699 links[1].AddTag(LogConstants.MessageEnqueuedTimeKey, link1EnqueuedTime.ToString());700 // simulate functions behavior to set request on the scope701 using (var _ = logger.BeginScope(new Dictionary<string, object> { ["Links"] = links }))702 {703 MethodInfo methodInfo = GetType().GetMethod(testName, BindingFlags.Public | BindingFlags.Static);704 await host.GetJobHost().CallAsync(methodInfo, new { input = "function input" });705 }706 await host.StopAsync();707 // Validate the request708 RequestTelemetry functionRequest = _channel.Telemetries.OfType<RequestTelemetry>().SingleOrDefault();709 Assert.True(functionRequest.Metrics.TryGetValue("timeSinceEnqueued", out var timeSinceEnqueued));710 var expectedTimeInQueue = functionRequest.Timestamp.ToUnixTimeMilliseconds() - link0EnqueuedTime;711 expectedTimeInQueue += Math.Max(functionRequest.Timestamp.ToUnixTimeMilliseconds() - link1EnqueuedTime, 0); // it's always 0 since link1EnqueuedTime is in the future712 expectedTimeInQueue /= 2; // there are two links713 Assert.Equal(expectedTimeInQueue, timeSinceEnqueued, 1);714 }715 }716 [Fact]717 public async Task ApplicationInsights_EventHubTrackingByWebJobs_MultipleLinks_TimeInQueueInconsistentlyPopulated()718 {719 string testName = nameof(TestApplicationInsightsInformation);720 using (IHost host = ConfigureHost())721 {722 Startup.Host = host;723 await host.StartAsync();724 var loggerProvider = host.Services.GetServices<ILoggerProvider>().OfType<ApplicationInsightsLoggerProvider>().Single();725 var logger = loggerProvider.CreateLogger(LogCategories.Results);726 var links = new Activity[2];727 links[0] = new Activity("link0").SetParentId(728 ActivityTraceId.CreateRandom(),729 ActivitySpanId.CreateRandom(),730 ActivityTraceFlags.Recorded);731 links[0].AddTag(LogConstants.MessageEnqueuedTimeKey, DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString());732 links[1] = new Activity("link1").SetParentId(733 ActivityTraceId.CreateRandom(),734 ActivitySpanId.CreateRandom());735 // simulate functions behavior to set request on the scope736 using (var _ = logger.BeginScope(new Dictionary<string, object> { ["Links"] = links }))737 {738 MethodInfo methodInfo = GetType().GetMethod(testName, BindingFlags.Public | BindingFlags.Static);739 await host.GetJobHost().CallAsync(methodInfo, new { input = "function input" });740 }741 await host.StopAsync();742 // Validate the request743 RequestTelemetry functionRequest = _channel.Telemetries.OfType<RequestTelemetry>().SingleOrDefault();744 Assert.False(functionRequest.Metrics.TryGetValue("timeSinceEnqueued", out var timeSinceEnqueued));745 }746 }747 [Theory]748 [InlineData(nameof(TestApplicationInsightsInformation), true)]749 [InlineData(nameof(TestApplicationInsightsFailure), false)]750 public async Task ApplicationInsights_HttpRequestTrackingByAIAutoCollector(string testName, bool success)751 {752 var client = _factory.CreateClient();753 using (IHost host = ConfigureHost())754 {755 Startup.Host = host;756 await host.StartAsync();757 var loggerProvider = host.Services.GetServices<ILoggerProvider>().OfType<ApplicationInsightsLoggerProvider>().Single();758 var logger = loggerProvider.CreateLogger(LogCategories.Results);759 var request = new HttpRequestMessage(HttpMethod.Get, $"/some/path?name={testName}");760 request.Headers.Add("X-Forwarded-For", "1.2.3.4");761 request.Headers.Add("traceparent", "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01");762 var mockHttpContext = new DefaultHttpContext();763 // simulate functions behavior to set request on the scope764 using (var _ = logger.BeginScope(new Dictionary<string, object> { ["MS_HttpRequest"] = mockHttpContext.Request }))765 {766 await client.SendAsync(request);767 }768 await host.StopAsync();769 // Validate the request770 // There must be only one reported by the AppInsights request collector771 // The telemetry may come back slightly later, so wait until we see it772 RequestTelemetry functionRequest = null;773 await TestHelpers.Await(() =>774 {775 functionRequest = _channel.Telemetries.OfType<RequestTelemetry>().SingleOrDefault();776 return functionRequest != null;777 });778 Assert.True(double.TryParse(functionRequest.Properties[LogConstants.FunctionExecutionTimeKey], out double functionDuration));779 Assert.True(functionRequest.Duration.TotalMilliseconds >= functionDuration);780 Assert.Equal("1.2.3.4", functionRequest.Context.Location.Ip);781 Assert.Equal("http://localhost/some/path", functionRequest.Url.ToString());782 ValidateRequest(783 functionRequest,784 testName,785 testName,786 "GET",787 "/some/path",788 success,789 "204",790 "4bf92f3577b34da6a3ce929d0e0e4736",791 "00f067aa0ba902b7");792 Assert.DoesNotContain("MS_HttpRequest", functionRequest.Properties.Keys);793 // Make sure operation ids match794 var traces = _channel.Telemetries.OfType<TraceTelemetry>()795 .Where(t => t.Context.Operation.Id == functionRequest.Context.Operation.Id).ToList();796 Assert.Equal(success ? 4 : 5, traces.Count);797 foreach (var trace in traces.Where(t => t.Context.Operation.ParentId == functionRequest.Id))798 {799 Assert.Equal("1.2.3.4", trace.Context.Location.Ip);800 }801 }802 }803 [Fact]804 public async Task ApplicationInsights_HttpRequestTrackingByWebJobsFirstRequest()805 {806 var client = _factory.CreateClient();807 var httpOptions = new HttpAutoCollectionOptions808 {809 EnableHttpTriggerExtendedInfoCollection = false810 };811 // simulate functions workaround to track first cold requests812 _requestModuleForFirstRequest.Initialize(null);813 using (IHost host = ConfigureHost(httpOptions: httpOptions))814 {815 Startup.Host = host;816 await host.StartAsync();817 var request = new HttpRequestMessage(HttpMethod.Get, $"/some/path?name={nameof(TestApplicationInsightsDisposeRequestsModule)}");818 await client.SendAsync(request);819 await host.StopAsync();820 // Validate the request821 // There must be only one reported by the AppInsights request collector822 // The telemetry may come back slightly later, so wait until we see it823 RequestTelemetry functionRequest = null;824 await TestHelpers.Await(() =>825 {826 functionRequest = _channel.Telemetries.OfType<RequestTelemetry>().SingleOrDefault();827 return functionRequest != null;828 });829 Assert.True(double.TryParse(functionRequest.Properties[LogConstants.FunctionExecutionTimeKey], out double functionDuration));830 Assert.True(functionRequest.Duration.TotalMilliseconds >= functionDuration);831 Assert.Null(functionRequest.Url);832 ValidateRequest(833 functionRequest,834 nameof(TestApplicationInsightsDisposeRequestsModule),835 nameof(TestApplicationInsightsDisposeRequestsModule),836 null,837 null,838 true);839 // Make sure operation ids match840 var traces = _channel.Telemetries.OfType<TraceTelemetry>()841 .Where(t => t.Context.Operation.Id == functionRequest.Context.Operation.Id);842 Assert.Equal(2, traces.Count());843 }844 }845 [Fact]846 public async Task ApplicationInsights_HttpRequestTrackingByAIAutoCollectorFirstRequest()847 {848 var client = _factory.CreateClient();849 // simulate functions workaround to track first cold requests850 _requestModuleForFirstRequest.Initialize(null);851 using (IHost host = ConfigureHost())852 {853 Startup.Host = host;854 await host.StartAsync();855 var request = new HttpRequestMessage(HttpMethod.Get, $"/some/path?name={nameof(TestApplicationInsightsDisposeRequestsModule)}");856 await client.SendAsync(request);857 await host.StopAsync();858 // Validate the request859 // There must be only one reported by the AppInsights request collector860 // The telemetry may come back slightly later, so wait until we see it861 RequestTelemetry functionRequest = null;862 await TestHelpers.Await(() =>863 {864 functionRequest = _channel.Telemetries.OfType<RequestTelemetry>().SingleOrDefault();865 return functionRequest != null;866 });867 Assert.True(double.TryParse(functionRequest.Properties[LogConstants.FunctionExecutionTimeKey], out double functionDuration));868 Assert.True(functionRequest.Duration.TotalMilliseconds >= functionDuration);869 Assert.Equal("http://localhost/some/path", functionRequest.Url.ToString());870 ValidateRequest(871 functionRequest,872 nameof(TestApplicationInsightsDisposeRequestsModule),873 nameof(TestApplicationInsightsDisposeRequestsModule),874 "GET",875 "/some/path",876 true,877 "204");878 // Make sure operation ids match879 var traces = _channel.Telemetries.OfType<TraceTelemetry>()880 .Where(t => t.Context.Operation.Id == functionRequest.Context.Operation.Id);881 Assert.Equal(2, traces.Count());882 }883 }884 [Fact]885 public async Task ApplicationInsights_HttpRequestTracking_IgnoresDuplicateRequests()886 {887 // During Functions host shutdown/restart events, it's possible to have two 888 // simultaneous running hosts for a very short period. We need to make sure we don't889 // double-log any of the auto-tracked Requests.890 var client = _factory.CreateClient();891 // Create two hosts to simulate.892 using (IHost host1 = ConfigureHost())893 {894 using (IHost host2 = ConfigureHost())895 {896 Startup.Host = host2;897 await host1.StartAsync();898 await host2.StartAsync();899 string testName = nameof(TestApplicationInsightsInformation);900 var request = new HttpRequestMessage(HttpMethod.Get, $"/some/path?name={testName}");901 request.Headers.Add("traceparent", "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01");902 await client.SendAsync(request);903 await host1.StopAsync();904 await host2.StopAsync();905 // Validate the request906 // There must be only one reported by the AppInsights request collector907 // The telemetry may come back slightly later, so wait until we see it908 RequestTelemetry functionRequest = null;909 await TestHelpers.Await(() =>910 {911 functionRequest = _channel.Telemetries.OfType<RequestTelemetry>().SingleOrDefault();912 return functionRequest != null;913 });914 Assert.True(double.TryParse(functionRequest.Properties[LogConstants.FunctionExecutionTimeKey], out double functionDuration));915 Assert.True(functionRequest.Duration.TotalMilliseconds >= functionDuration);916 ValidateRequest(917 functionRequest,918 testName,919 testName,920 "GET",921 "/some/path",922 true,923 "204",924 "4bf92f3577b34da6a3ce929d0e0e4736",925 "00f067aa0ba902b7");926 Assert.Equal(_expectedResponseCode.ToString(), functionRequest.ResponseCode);927 }928 }929 }930 // Test Functions931 [NoAutomaticTrigger]932 public static void TestApplicationInsightsInformation(string input, TraceWriter trace, ILogger logger)933 {934 // Wrap in a custom scope with custom properties.935 using (logger.BeginScope(new Dictionary<string, object>936 {937 [_customScopeKey] = _customScopeValue938 }))939 {940 trace.Info("Trace");941 logger.LogInformation("Logger");942 logger.LogMetric("MyCustomMetric", 5.1, new Dictionary<string, object>943 {944 ["MyCustomMetricProperty"] = 100,945 ["Count"] = 50,946 ["min"] = 10.4,947 ["Max"] = 23948 });949 }950 }951 [NoAutomaticTrigger]952 public static void TestApplicationInsightsFailure(string input, TraceWriter trace, ILogger logger)953 {954 // Wrap in a custom scope with custom properties, using the structured logging approach.955 using (logger.BeginScope($"{{{_customScopeKey}}}", _customScopeValue))956 {957 trace.Info("Trace");958 logger.LogInformation("Logger");959 // Note: Exceptions thrown do *not* have the custom scope properties attached because960 // the logging doesn't occur until after the scope has left. Logging an Exception directly 961 // will have the proper scope attached.962 logger.LogError(new Exception("Boom 1!"), "Error");963 throw new Exception("Boom 2!");964 }965 }966 [NoAutomaticTrigger]967 public static void TestApplicationInsightsWarning(TraceWriter trace, ILogger logger)968 {969 trace.Warning("Trace");970 logger.LogWarning("Logger");971 }972 [NoAutomaticTrigger]973 public static void TestApplicationInsightsExplicitCall(ILogger logger)974 {975 TelemetryClient telemetryClient = new TelemetryClient(); // use TelemetryConfiguration.Active976 telemetryClient.TrackEvent("custom event");977 }978 [NoAutomaticTrigger]979 public static void TestApplicationInsightsStartOperation(TelemetryClient telemetryClient, bool testRequestTelemetry, string customOperationId)980 {981 OperationTelemetry operationTelemetry = testRequestTelemetry ? new RequestTelemetry() : (OperationTelemetry)new DependencyTelemetry();982 operationTelemetry.Name = "custom";983 if (customOperationId != null)984 {985 operationTelemetry.Context.Operation.Id = customOperationId;986 }987 using (telemetryClient.StartOperation(operationTelemetry)) { }988 }989 [NoAutomaticTrigger]990 public static void TestApplicationInsightsDisposeRequestsModule(string input, ILogger logger)991 {992 _requestModuleForFirstRequest.Dispose();993 }994 [NoAutomaticTrigger]995 public static void TestApplicationInsightsCheckActivityFormat(ActivityIdFormat expected, ILogger logger)996 {997 Assert.Equal(expected, Activity.Current.IdFormat);998 }999 private static void ValidateMetric(MetricTelemetry telemetry, string expectedOperationName)1000 {1001 Assert.Equal(expectedOperationName, telemetry.Context.Operation.Name);1002 Assert.NotNull(telemetry.Context.Operation.Id);1003 Assert.Equal(LogCategories.CreateFunctionUserCategory(expectedOperationName), telemetry.Properties[LogConstants.CategoryNameKey]);1004 Assert.Equal(LogLevel.Information.ToString(), telemetry.Properties[LogConstants.LogLevelKey]);1005 Assert.Equal("MyCustomMetric", telemetry.Name);1006 Assert.Equal(5.1, telemetry.Sum);1007 Assert.Equal(50, telemetry.Count);1008 Assert.Equal(10.4, telemetry.Min);1009 Assert.Equal(23, telemetry.Max);1010 Assert.Null(telemetry.StandardDeviation);1011 Assert.Equal("100", telemetry.Properties[$"{LogConstants.CustomPropertyPrefix}MyCustomMetricProperty"]);1012 ValidateCustomScopeProperty(telemetry);1013 ValidateSdkVersion(telemetry, "af_");1014 }1015 private static void ValidateCustomScopeProperty(ISupportProperties telemetry)1016 {1017 Assert.Equal(_customScopeValue, telemetry.Properties[$"{LogConstants.CustomPropertyPrefix}{_customScopeKey}"]);1018 }1019 private class ApplicationInsightsTestListener : IDisposable1020 {1021 private readonly HttpListener _applicationInsightsListener = new HttpListener();1022 private Task _listenTask;1023 private int _posts;1024 private readonly ConcurrentQueue<QuickPulsePayload> _quickPulseItems = new ConcurrentQueue<QuickPulsePayload>();1025 private CancellationTokenSource _tcs;1026 public IEnumerable<QuickPulsePayload> GetQuickPulseItems()1027 {1028 return _quickPulseItems.ToList();1029 }1030 // Make sure collection has started.1031 public bool IsReady => _posts >= 2;1032 public void StartListening()1033 {1034 _tcs = new CancellationTokenSource();1035 _applicationInsightsListener.Prefixes.Add(_mockApplicationInsightsUrl);1036 _applicationInsightsListener.Prefixes.Add(_mockQuickPulseUrl);1037 _applicationInsightsListener.Start();1038 _listenTask = Listen(_tcs.Token);1039 }1040 public void StopListening()1041 {1042 _tcs?.Cancel(false);1043 if (_listenTask != null && !_listenTask.IsCompleted)1044 {1045 _listenTask.Wait();1046 }1047 _applicationInsightsListener.Stop();1048 _tcs?.Dispose();1049 _listenTask = null;1050 }1051 private Task Listen(CancellationToken cancellationToken)1052 {1053 // process a request, then continue to wait for the next1054 return Task.Run(async () =>1055 {1056 while (_applicationInsightsListener.IsListening && !cancellationToken.IsCancellationRequested)1057 {1058 try1059 {1060 HttpListenerContext context = await _applicationInsightsListener.GetContextAsync().ConfigureAwait(false);1061 ProcessRequest(context);1062 }1063 catch (Exception e) when (e is ObjectDisposedException || e is HttpListenerException)1064 {1065 // This can happen when stopping the listener.1066 }1067 }1068 });1069 }1070 private void ProcessRequest(HttpListenerContext context)1071 {1072 HttpListenerRequest request = context.Request;1073 HttpListenerResponse response = context.Response;1074 try1075 {1076 if (request.Url.OriginalString.StartsWith(_mockQuickPulseUrl))1077 {1078 HandleQuickPulseRequest(request, response);1079 }1080 else1081 {1082 throw new NotSupportedException();1083 }1084 }1085 finally1086 {1087 response.Close();1088 }1089 }1090 private void HandleQuickPulseRequest(HttpListenerRequest request, HttpListenerResponse response)1091 {1092 string result = GetRequestContent(request);1093 response.AddHeader("x-ms-qps-subscribed", true.ToString());1094 if (request.Url.LocalPath == "/QuickPulseService.svc/post")1095 {1096 QuickPulsePayload[] quickPulse = JsonConvert.DeserializeObject<QuickPulsePayload[]>(result);1097 foreach (QuickPulsePayload i in quickPulse)1098 {1099 _quickPulseItems.Enqueue(i);1100 }1101 _posts++;1102 }1103 }1104 private static string GetRequestContent(HttpListenerRequest request)1105 {1106 string result = null;1107 if (request.HasEntityBody)1108 {1109 using (Stream requestInputStream = request.InputStream)1110 {1111 Encoding encoding = request.ContentEncoding;1112 using (StreamReader reader = new StreamReader(requestInputStream, encoding))1113 {1114 result = reader.ReadToEnd();1115 }1116 }1117 }1118 return result;1119 }1120 private static string Decompress(string content)1121 {1122 byte[] zippedData = Encoding.Default.GetBytes(content);1123 using (MemoryStream ms = new MemoryStream(zippedData))1124 {1125 using (GZipStream compressedzipStream = new GZipStream(ms, CompressionMode.Decompress))1126 {1127 MemoryStream outputStream = new MemoryStream();1128 byte[] block = new byte[1024];1129 while (true)1130 {1131 int bytesRead = compressedzipStream.Read(block, 0, block.Length);1132 if (bytesRead <= 0)1133 {1134 break;1135 }1136 outputStream.Write(block, 0, bytesRead);1137 }1138 compressedzipStream.Close();1139 return Encoding.UTF8.GetString(outputStream.ToArray());1140 }1141 }1142 }1143 public void Dispose()1144 {1145 _applicationInsightsListener.Stop();1146 _applicationInsightsListener.Close();1147 (_applicationInsightsListener as IDisposable)?.Dispose();1148 }1149 }1150 private static void ValidateTrace(TraceTelemetry telemetry, string expectedMessageStartsWith, string expectedCategory,1151 string expectedOperationName = null, string expectedInvocationId = null, string expectedOperationId = null,1152 string expectedParentId = null, bool hasCustomScope = false, LogLevel expectedLogLevel = LogLevel.Information)1153 {1154 Assert.StartsWith(expectedMessageStartsWith, telemetry.Message);1155 Assert.Equal(GetSeverityLevel(expectedLogLevel), telemetry.SeverityLevel);1156 Assert.Equal(expectedCategory, telemetry.Properties[LogConstants.CategoryNameKey]);1157 if (hasCustomScope)1158 {1159 ValidateCustomScopeProperty(telemetry);1160 }1161 if (expectedCategory == LogCategories.CreateFunctionCategory(expectedOperationName) ||1162 expectedCategory == LogCategories.CreateFunctionUserCategory(expectedOperationName))1163 {1164 // These should have associated operation information1165 Assert.Equal(expectedOperationName, telemetry.Context.Operation.Name);1166 Assert.Equal(expectedOperationId, telemetry.Context.Operation.Id);1167 Assert.Equal(expectedParentId, telemetry.Context.Operation.ParentId);1168 Assert.True(telemetry.Properties.TryGetValue(LogConstants.InvocationIdKey, out string id));1169 Assert.Equal(expectedInvocationId, id);1170 }1171 else1172 {1173 Assert.Null(telemetry.Context.Operation.Name);1174 Assert.Null(telemetry.Context.Operation.Id);1175 Assert.Null(telemetry.Context.Operation.ParentId);1176 Assert.False(telemetry.Properties.TryGetValue(LogConstants.InvocationIdKey, out string unused));1177 }1178 ValidateSdkVersion(telemetry);1179 }1180 private static SeverityLevel GetSeverityLevel(LogLevel logLevel)1181 {1182 switch (logLevel)1183 {1184 case LogLevel.Trace:1185 case LogLevel.Debug:1186 return SeverityLevel.Verbose;1187 case LogLevel.Information:1188 return SeverityLevel.Information;1189 case LogLevel.Warning:1190 return SeverityLevel.Warning;1191 case LogLevel.Error:1192 return SeverityLevel.Error;1193 case LogLevel.Critical:1194 return SeverityLevel.Critical;1195 case LogLevel.None:1196 default:1197 throw new InvalidOperationException();1198 }1199 }1200 private static void ValidateException(1201 ExceptionTelemetry telemetry,1202 string expectedCategory,1203 string expectedOperationName,1204 string expectedOperationId,1205 string expectedParentId)1206 {1207 Assert.Equal(expectedCategory, telemetry.Properties[LogConstants.CategoryNameKey]);1208 Assert.Equal(expectedOperationName, telemetry.Context.Operation.Name);1209 Assert.Equal(expectedOperationId, telemetry.Context.Operation.Id);1210 Assert.Equal(expectedParentId, telemetry.Context.Operation.ParentId);1211 if (expectedCategory == LogCategories.CreateFunctionUserCategory(expectedOperationName))1212 {1213 // It came directly from the user1214 Assert.IsType<Exception>(telemetry.Exception);1215 // Result logs do not include custom scopes.1216 ValidateCustomScopeProperty(telemetry);1217 }1218 else if (expectedCategory == LogCategories.CreateFunctionCategory(expectedOperationName))1219 {1220 // It came directly from the host, so wrapped in a FunctionInvocationException1221 Assert.IsType<FunctionInvocationException>(telemetry.Exception);1222 }1223 else if (expectedCategory == LogCategories.Results)1224 {1225 // Check that the Function details show up as 'prop__'. We may change this in the future as1226 // it may not be exceptionally useful.1227 Assert.Equal(expectedOperationName, telemetry.Properties[$"{LogConstants.CustomPropertyPrefix}{LogConstants.NameKey}"]);1228 Assert.Equal("This function was programmatically called via the host APIs.", telemetry.Properties[$"{LogConstants.CustomPropertyPrefix}{LogConstants.TriggerReasonKey}"]);1229 Assert.IsType<FunctionInvocationException>(telemetry.Exception);1230 Assert.IsType<Exception>(telemetry.Exception.InnerException);1231 }1232 ValidateSdkVersion(telemetry);1233 }1234 private static void ValidateRequest(RequestTelemetry telemetry, string operationName, string name, string httpMethod, string requestPath, bool success, string statusCode = "0",1235 string operationId = null, string parentId = null)1236 {1237 Assert.NotNull(telemetry.Context.Operation.Id);1238 Assert.Equal(operationName, telemetry.Context.Operation.Name);1239 Assert.NotNull(telemetry.Duration);1240 Assert.Equal(success, telemetry.Success);1241 Assert.NotNull(telemetry.Properties[LogConstants.InvocationIdKey]);1242 Assert.Equal($"ApplicationInsightsEndToEndTests.{operationName}", telemetry.Properties[LogConstants.FullNameKey]);1243 Assert.Equal("This function was programmatically called via the host APIs.", telemetry.Properties[LogConstants.TriggerReasonKey]);1244 TelemetryValidationHelpers.ValidateRequest(telemetry, operationName, name, operationId, parentId, LogCategories.Results,1245 success ? LogLevel.Information : LogLevel.Error, success, statusCode);1246 }1247 private static void ValidateSdkVersion(ITelemetry telemetry, string prefix = null)1248 {1249 Assert.StartsWith($"{prefix}webjobs:", telemetry.Context.GetInternalContext().SdkVersion);1250 }1251 private class QuickPulsePayload1252 {1253 public string Instance { get; set; }1254 public DateTime Timestamp { get; set; }1255 public string StreamId { get; set; }1256 public QuickPulseMetric[] Metrics { get; set; }1257 public override string ToString()1258 {1259 string s = string.Join(Environment.NewLine, Metrics.Select(m => $" {m}"));1260 return $"[{Timestamp.ToString(_dateFormat)}] Metrics:{Environment.NewLine}{s}";1261 }1262 }1263 private class QuickPulseMetric1264 {1265 public string Name { get; set; }1266 public double Value { get; set; }1267 public int Weight { get; set; }1268 public override string ToString()1269 {1270 return $"{Name}: {Value} ({Weight})";1271 }1272 }1273 // For debugging QuickPulse failures1274 private class QuickPulseEventListener : EventListener1275 {1276 private readonly IList<string> _logs = new List<string>();1277 public string GetLog(int lines)1278 {1279 return string.Join(Environment.NewLine, _logs.Take(lines));1280 }1281 protected override void OnEventWritten(EventWrittenEventArgs eventData)1282 {1283 List<object> trimmedData = eventData.Payload.ToList();1284 trimmedData.RemoveAt(trimmedData.Count - 1);1285 string log = string.Format(eventData.Message, trimmedData.ToArray());1286 _logs.Add($"[{DateTime.UtcNow.ToString(_dateFormat)}] {log}");1287 base.OnEventWritten(eventData);1288 }1289 protected override void OnEventSourceCreated(EventSource eventSource)1290 {1291 if (eventSource.Name == "Microsoft-ApplicationInsights-Extensibility-PerformanceCollector-QuickPulse")1292 {1293 EnableEvents(eventSource, EventLevel.LogAlways);1294 }1295 base.OnEventSourceCreated(eventSource);1296 }1297 }1298 public void Dispose()1299 {1300 _channel?.Dispose();1301 while (Activity.Current != null)1302 {1303 Activity.Current.Stop();1304 }1305 }1306 public class Startup1307 {1308 public static IHost Host;1309 public void ConfigureServices(IServiceCollection services)1310 {1311 services.AddHttpContextAccessor();1312 }1313 public void Configure(IApplicationBuilder app, AspNetCore.Hosting.IHostingEnvironment env)1314 {...

Full Screen

Full Screen

AppVeyorReporterMessageHandler.cs

Source:AppVeyorReporterMessageHandler.cs Github

copy

Full Screen

...53 {54 assembliesInFlight--;55 if (assembliesInFlight == 0)56 {57 client?.Dispose(CancellationToken.None);58 client = null;59 }60 }61 }62 void HandleTestAssemblyStarting(MessageHandlerArgs<ITestAssemblyStarting> args)63 {64 lock (clientLock)65 {66 assembliesInFlight++;67 // Look for the TFM attrib to disambiguate68 var attrib = args.Message.TestAssembly.Assembly.GetCustomAttributes("System.Runtime.Versioning.TargetFrameworkAttribute").FirstOrDefault();69 var assemblyFileName = Path.GetFileName(args.Message.TestAssembly.Assembly.AssemblyPath);70 if (attrib?.GetConstructorArguments().FirstOrDefault() is string arg)71 assemblyFileName = $"{assemblyFileName} ({arg})";...

Full Screen

Full Screen

AppVeyorClient.cs

Source:AppVeyorClient.cs Github

copy

Full Screen

...28 this.logger = logger;29 this.baseUri = $"{baseUri}/api/tests/batch";30 Task.Run(RunLoop);31 }32 public void Dispose(CancellationToken cancellationToken)33 {34 // Free up to process any remaining work35 shouldExit = true;36 workEvent.Set();37 finished.Wait(cancellationToken);38 finished.Dispose();39 }40 async Task RunLoop()41 {42 try43 {44 while (!shouldExit || !addQueue.IsEmpty || !updateQueue.IsEmpty)45 {46 workEvent.Wait(); // Wait for work47 workEvent.Reset(); // Reset first to ensure any subsequent modification sets48 // Get local copies of the queues49 var aq = Interlocked.Exchange(ref addQueue, new ConcurrentQueue<IDictionary<string, object?>>());50 var uq = Interlocked.Exchange(ref updateQueue, new ConcurrentQueue<IDictionary<string, object?>>());51 if (previousErrors)52 break;...

Full Screen

Full Screen

Dispose

Using AI Code Generation

copy

Full Screen

1using Xunit.Runner.Common;2{3 {4 static void Main(string[] args)5 {6 AppVeyorClient client = new AppVeyorClient();7 client.Dispose();8 }9 }10}11using Xunit.Runner.Common;12{13 {14 static void Main(string[] args)15 {16 AppVeyorClient client = new AppVeyorClient();17 client.Dispose();18 }19 }20}21using Xunit.Runner.Common;22{23 {24 static void Main(string[] args)25 {26 AppVeyorClient client = new AppVeyorClient();27 client.Dispose();28 }29 }30}31using Xunit.Runner.Common;32{33 {34 static void Main(string[] args)35 {36 AppVeyorClient client = new AppVeyorClient();37 client.Dispose();38 }39 }40}41using Xunit.Runner.Common;42{43 {44 static void Main(string[] args)45 {46 AppVeyorClient client = new AppVeyorClient();47 client.Dispose();48 }49 }50}51using Xunit.Runner.Common;52{53 {54 static void Main(string[] args)55 {56 AppVeyorClient client = new AppVeyorClient();57 client.Dispose();58 }59 }60}61using Xunit.Runner.Common;

Full Screen

Full Screen

Dispose

Using AI Code Generation

copy

Full Screen

1using Xunit.Runner.Common;2using Xunit.Runner.Common.AppVeyorClient;3{4 {5 public void Dispose()6 {7 throw new NotImplementedException();8 }9 }10}11using Xunit.Runner.Common.AppVeyorClient;12{13 {14 public void Dispose()15 {16 throw new NotImplementedException();17 }18 }19}20using Xunit.Runner.Common.AppVeyorClient;21{22 {23 public void Dispose()24 {25 throw new NotImplementedException();26 }27 }28}29using Xunit.Runner.Common.AppVeyorClient;30{31 {32 public void Dispose()33 {34 throw new NotImplementedException();35 }36 }37}38using Xunit.Runner.Common.AppVeyorClient;39{40 {41 public void Dispose()42 {43 throw new NotImplementedException();44 }45 }46}47using Xunit.Runner.Common.AppVeyorClient;48{49 {50 public void Dispose()51 {52 throw new NotImplementedException();53 }54 }55}56using Xunit.Runner.Common.AppVeyorClient;57{

Full Screen

Full Screen

Dispose

Using AI Code Generation

copy

Full Screen

1using Xunit.Runner.Common;2using Xunit.Runner.Common.AppVeyor;3using Xunit.Runner.Common.AppVeyor.Client;4using Xunit.Runner.Common.AppVeyor.Data;5using Xunit.Runner.Common.AppVeyor.Data.Api;6using Xunit.Runner.Common.AppVeyor.Data.AppVeyor;7using Xunit.Runner.Common.AppVeyor.Data.AppVeyor.Build;8using Xunit.Runner.Common.AppVeyor.Data.AppVeyor.Project;9using Xunit.Runner.Common.AppVeyor.Data.AppVeyor.Projects;10using Xunit.Runner.Common.AppVeyor.Data.AppVeyor.Projects.Builds;11using Xunit.Runner.Common.AppVeyor.Data.AppVeyor.Projects.Builds.Jobs;12using Xunit.Runner.Common.AppVeyor.Data.AppVeyor.Projects.Builds.Jobs.Log;13using Xunit.Runner.Common.AppVeyor.Data.AppVeyor.Projects.Builds.Jobs.Logs;14using Xunit.Runner.Common.AppVeyor.Data.AppVeyor.Projects.Builds.Jobs.Test;15using Xunit.Runner.Common.AppVeyor.Data.AppVeyor.Projects.Builds.Jobs.Tests;16using Xunit.Runner.Common.AppVeyor.Data.AppVeyor.Projects.Builds.Jobs.Tests.Test;17using Xunit.Runner.Common.AppVeyor.Data.AppVeyor.Projects.Builds.Jobs.Tests.Tests;18using Xunit.Runner.Common.AppVeyor.Data.AppVeyor.Projects.Builds.Jobs.Tests.Tests.Test;19using Xunit.Runner.Common.AppVeyor.Data.AppVeyor.Projects.Builds.Jobs.Tests.Tests.Tests;20using Xunit.Runner.Common.AppVeyor.Data.AppVeyor.Projects.Builds.Jobs.Tests.Tests.Tests.Test;21using Xunit.Runner.Common.AppVeyor.Data.AppVeyor.Projects.Builds.Jobs.Tests.Tests.Tests.Tests;22using Xunit.Runner.Common.AppVeyor.Data.AppVeyor.Projects.Builds.Jobs.Tests.Tests.Tests.Tests.Test;23using Xunit.Runner.Common.AppVeyor.Data.AppVeyor.Projects.Builds.Jobs.Tests.Tests.Tests.Tests.Tests;24using Xunit.Runner.Common.AppVeyor.Data.AppVeyor.Projects.Builds.Jobs.Tests.Tests.Tests.Tests.Tests.Test;25using Xunit.Runner.Common.AppVeyor.Data.AppVeyor.Projects.Builds.Jobs.Tests.Tests.Tests.Tests.Tests.Tests;

Full Screen

Full Screen

Dispose

Using AI Code Generation

copy

Full Screen

1using Xunit.Runner.Common;2using Xunit.Runner.Common.AppVeyorClient;3using Xunit.Runner.Common.AppVeyorClient.Model;4using Xunit.Runner.Common.AppVeyorClient.Model.Builds;5using Xunit.Runner.Common.AppVeyorClient.Model.Projects;6using Xunit.Runner.Common.AppVeyorClient.Model.Projects.Project;7using Xunit.Runner.Common.AppVeyorClient.Model.Projects.Project.Builds;8using Xunit.Runner.Common.AppVeyorClient.Model.Projects.Project.Builds.Build;9using Xunit.Runner.Common.AppVeyorClient.Model.Projects.Project.Builds.Build.Job;10using Xunit.Runner.Common.AppVeyorClient.Model.Projects.Project.Builds.Build.Job.Log;11using Xunit.Runner.Common.AppVeyorClient.Model.Projects.Project.Builds.Build.Job.Logs;12using Xunit.Runner.Common.AppVeyorClient.Model.Projects.Project.Builds.Build.Jobs;13using Xunit.Runner.Common.AppVeyorClient.Model.Projects.Project.Builds.Build.Jobs.Job;14using Xunit.Runner.Common.AppVeyorClient.Model.Projects.Project.Builds.Build.Jobs.Job.Log;15using Xunit.Runner.Common.AppVeyorClient.Model.Projects.Project.Builds.Build.Jobs.Job.Logs;16using Xunit.Runner.Common.AppVeyorClient.Model.Projects.Project.Builds.Build.Jobs.Jobs;17using Xunit.Runner.Common.AppVeyorClient.Model.Projects.Project.Builds.Build.Jobs.Jobs.Job;18using Xunit.Runner.Common.AppVeyorClient.Model.Projects.Project.Builds.Build.Jobs.Jobs.Job.Log;19using Xunit.Runner.Common.AppVeyorClient.Model.Projects.Project.Builds.Build.Jobs.Jobs.Job.Logs;20using Xunit.Runner.Common.AppVeyorClient.Model.Projects.Project.Builds.Build.Jobs.Jobs.Jobs;21using Xunit.Runner.Common.AppVeyorClient.Model.Projects.Project.Builds.Build.Jobs.Jobs.Jobs.Job;22using Xunit.Runner.Common.AppVeyorClient.Model.Projects.Project.Builds.Build.Jobs.Jobs.Jobs.Job.Log;23using Xunit.Runner.Common.AppVeyorClient.Model.Projects.Project.Builds.Build.Jobs.Jobs.Jobs.Job.Logs;24using Xunit.Runner.Common.AppVeyorClient.Model.Projects.Project.Builds.Build.Jobs.Jobs.Jobs.Jobs;

Full Screen

Full Screen

Dispose

Using AI Code Generation

copy

Full Screen

1using Xunit.Runner.Common;2var client = new AppVeyorClient();3client.Dispose();4using Xunit.Runner.Common;5var client = new AppVeyorClient();6((IAppVeyorClient)client).Dispose();7using Xunit.Runner.Common;8using Xunit.Runner.Common.IAppVeyorClient;9var client = new AppVeyorClient();10client.Dispose();11using Xunit.Runner.Common;12var client = new AppVeyorClient();13client.Dispose();14using Xunit.Runner.Common;15var client = new AppVeyorClient();16((IAppVeyorClient)client).Dispose();17using Xunit.Runner.Common;18using Xunit.Runner.Common.IAppVeyorClient;19var client = new AppVeyorClient();20client.Dispose();

Full Screen

Full Screen

Dispose

Using AI Code Generation

copy

Full Screen

1using Xunit.Runner.Common;2{3 {4 public AppVeyorClient()5 {6 if (Environment.GetEnvironmentVariable("APPVEYOR") == "True")7 {8 Console.WriteLine("##teamcity[progressStart 'Running tests']");9 }10 }11 public void Dispose()12 {13 if (Environment.GetEnvironmentVariable("APPVEYOR") == "True")14 {15 Console.WriteLine("##teamcity[progressFinish 'Running tests']");16 }17 }18 }19}20using Xunit.Runner.Common;21{22 {23 public AppVeyorClient()24 {25 if (Environment.GetEnvironmentVariable("APPVEYOR") == "True")26 {27 Console.WriteLine("##teamcity[progressStart 'Running tests']");28 }29 }30 public void Dispose()31 {32 if (Environment.GetEnvironmentVariable("APPVEYOR") == "True")33 {34 Console.WriteLine("##teamcity[progressFinish 'Running tests']");35 }36 }37 }38}39{40 public void Test1()41 {42 using (new AppVeyorClient())43 {44 }45 }46}

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 AppVeyorClient

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful