Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky tests in WindowsServiceLifetimeTests #105666

Merged
merged 2 commits into from
Aug 7, 2024

Conversation

buyaa-n
Copy link
Member

@buyaa-n buyaa-n commented Jul 30, 2024

  • ServiceCanStopItself test fails with System.ServiceProcess.TimeoutException : The operation requested for service 'ServiceCanStopItself' has not been completed within the specified time interval. The interval is 30 milliseconds, changing it to TimeSpan.MaxValue because the test is expected to stop eventually, it's not defined what time interval will be enough.
  • ServiceSequenceIsCorrect test fails because of race condition, it looks serviceTester.Stop() started before serviceTester.Start() completed. It was suggested to introduce a synchronization primitive here and have the test wait for that to be signaled by the service. Added AutoResetEvent instance that signals when windows service started completely

Fixes #103262
Fixes #93194

Copy link
Member

@ericstj ericstj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me. Make sure you run the impacted tests in case they don't run in normal PR validation.

@steveharter
Copy link
Member

Looks reasonable to me. Make sure you run the impacted tests in case they don't run in normal PR validation.

Ran a few times locally in admin command prompt + Windows:

  Discovering: Microsoft.Extensions.Hosting.WindowsServices.Tests (app domain = on [no shadow copy], method display = ClassAndMethod, method display options = None)
  Discovered:  Microsoft.Extensions.Hosting.WindowsServices.Tests (found 11 of 12 test cases)
  Starting:    Microsoft.Extensions.Hosting.WindowsServices.Tests (parallel test collections = on [20 threads], stop on fail = off)
   Microsoft.Extensions.Hosting.WindowsServiceLifetimeTests.ServiceStops [STARTING]
    Microsoft.Extensions.Hosting.UseWindowsServiceTests.DefaultsToOffOutsideOfService [STARTING]
    Microsoft.Extensions.Hosting.UseWindowsServiceTests.DefaultsToOffOutsideOfService [FINISHED] Time: 0.1712331s
    Microsoft.Extensions.Hosting.UseWindowsServiceTests.ServiceCollectionExtensionMethodAddsWindowsServiceLifetimeInsideOfService [STARTING]
    Microsoft.Extensions.Hosting.UseWindowsServiceTests.ServiceCollectionExtensionMethodAddsWindowsServiceLifetimeInsideOfService [FINISHED] Time: 0.0623185s
    Microsoft.Extensions.Hosting.UseWindowsServiceTests.ServiceCollectionExtensionMethodDefaultsToOffOutsideOfService [STARTING]
    Microsoft.Extensions.Hosting.UseWindowsServiceTests.ServiceCollectionExtensionMethodDefaultsToOffOutsideOfService [FINISHED] Time: 0.0086278s
    Microsoft.Extensions.Hosting.UseWindowsServiceTests.CanCreateService [STARTING]
    Microsoft.Extensions.Hosting.WindowsServiceLifetimeTests.ServiceStops [FINISHED] Time: 0.4462791s
    Microsoft.Extensions.Hosting.WindowsServiceLifetimeTests.ExceptionOnStopIsPropagated [STARTING]
    Microsoft.Extensions.Hosting.UseWindowsServiceTests.CanCreateService [FINISHED] Time: 0.4668568s
    Microsoft.Extensions.Hosting.UseWindowsServiceTests.ServiceCollectionExtensionMethodCanBeCalledOnDefaultConfiguration [STARTING]
    Microsoft.Extensions.Hosting.UseWindowsServiceTests.ServiceCollectionExtensionMethodCanBeCalledOnDefaultConfiguration [FINISHED] Time: 0.0022696s
    Microsoft.Extensions.Hosting.UseWindowsServiceTests.ServiceCollectionExtensionMethodSetsEventLogSourceNameToApplicationNameInsideOfService [STARTING]
    Microsoft.Extensions.Hosting.UseWindowsServiceTests.ServiceCollectionExtensionMethodSetsEventLogSourceNameToApplicationNameInsideOfService [FINISHED] Time: 0.0015367s
    Microsoft.Extensions.Hosting.WindowsServiceLifetimeTests.ExceptionOnStopIsPropagated [FINISHED] Time: 0.3454064s
    Microsoft.Extensions.Hosting.WindowsServiceLifetimeTests.ServiceSequenceIsCorrect [STARTING]
    Microsoft.Extensions.Hosting.WindowsServiceLifetimeTests.ServiceSequenceIsCorrect [FINISHED] Time: 1.4618799s
    Microsoft.Extensions.Hosting.WindowsServiceLifetimeTests.CancelStopAsync [STARTING]
    Microsoft.Extensions.Hosting.WindowsServiceLifetimeTests.CancelStopAsync [FINISHED] Time: 0.0821135s
    Microsoft.Extensions.Hosting.WindowsServiceLifetimeTests.ServiceCanStopItself [STARTING]
    Microsoft.Extensions.Hosting.WindowsServiceLifetimeTests.ServiceCanStopItself [FINISHED] Time: 0.4354667s
  Finished:    Microsoft.Extensions.Hosting.WindowsServices.Tests
=== TEST EXECUTION SUMMARY ===
   Microsoft.Extensions.Hosting.WindowsServices.Tests  Total: 11, Errors: 0, Failed: 0, Skipped: 0, Time: 2.840s

@steveharter
Copy link
Member

Merging; Buyaa out

@steveharter steveharter merged commit 9616edd into dotnet:main Aug 7, 2024
82 of 84 checks passed
@steveharter steveharter deleted the windows-service branch August 7, 2024 18:31
@github-actions github-actions bot locked and limited conversation to collaborators Sep 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants