Skip to content

Add script that runs tests as a Windows service#239

Merged
edwards-aws merged 3 commits intoOpenJobDescription:mainlinefrom
edwards-aws:add_service_script
Jun 3, 2025
Merged

Add script that runs tests as a Windows service#239
edwards-aws merged 3 commits intoOpenJobDescription:mainlinefrom
edwards-aws:add_service_script

Conversation

@edwards-aws
Copy link
Copy Markdown
Contributor

What was the problem/requirement? (What/Why)

We're missing any easy way to run the tests as a Windows service. This is important because Windows has some different behaviour in session 0

What was the solution? (How)

Add a script that installs the tests as a service, then runs them.

What is the impact of this change?

Contributors can now run tests easily in session 0 directly as a service.

How was this change tested?

Ran the tests with the script

Was this change documented?

Ya

Is this a breaking change?

Nope

Does this change impact security?

Nope

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@edwards-aws edwards-aws requested a review from a team as a code owner June 3, 2025 17:01
Comment thread scripts/windows_service_test.py Fixed
Signed-off-by: Cody Edwards <edwards@amazon.com>
@edwards-aws edwards-aws force-pushed the add_service_script branch from b1fd7a5 to 10e8dc8 Compare June 3, 2025 18:20
Comment thread DEVELOPMENT.md Outdated
1. `win32` doesn't work well in virtual environments, so it's more reliable to run with the system Python. The wheel file name will change depending the date and the version that the git branch is based off of.
1. Install the service by running `python scripts\windows_service_test.py install --user-name <UserYouWantRunningTheService> --pytest-args="<AnyAdditionalPytestArgsYou'dWantToPassIn>"`
1. Run the test in the service by running `python scripts\windows_service_test.py run`
1. You'll find the test output in the root project directory under `test.log`, the tests will live right to the log file.
Copy link
Copy Markdown
Contributor

@epmog epmog Jun 3, 2025

Choose a reason for hiding this comment

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

will live right to the log file.

right next? Might make a bit more sense to also swap it around. The user can specify the location of the tests, and the log file is created beside the tests that are run (not the other way around)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I did bad grammar here. I'll fix

Signed-off-by: Cody Edwards <edwards@amazon.com>
@edwards-aws edwards-aws force-pushed the add_service_script branch from 69c2dec to 570952a Compare June 3, 2025 18:41
jusiskin
jusiskin previously approved these changes Jun 3, 2025
Copy link
Copy Markdown
Contributor

@jusiskin jusiskin left a comment

Choose a reason for hiding this comment

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

Looks good. Just a few non-critical suggested improvements but not merge-blocking.

Comment thread DEVELOPMENT.md Outdated
2. Use the `scripts\windows_service_test.py` to test in the context of a service running session 0
1. `hatch build`
1. `pip install --force-reinstall dist\openjd_sessions*.whl`
1. `win32` doesn't work well in virtual environments, so it's more reliable to run with the system Python. The wheel file name will change depending the date and the version that the git branch is based off of.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did you mean pywin32?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes will fix

Comment thread DEVELOPMENT.md Outdated
Comment on lines +209 to +211
1. Install the service by running `python scripts\windows_service_test.py install --user-name <UserYouWantRunningTheService> --pytest-args="<AnyAdditionalPytestArgsYou'dWantToPassIn>"`
1. Run the test in the service by running `python scripts\windows_service_test.py run`
1. You'll find the test output in the root project directory under `test.log`, the tests will live right to the log file.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if we could combine these three steps into a single hatch command so you just run:

hatch run test-service --user-name <UserYouWantRunningTheService> --pytest-args="<AnyAdditionalPytestArgsYou'dWantToPassIn>"

not strictly required, but just a nice convenience if it is not too much effort. Bonus points for cleaning up the log file after.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I had considered that. I wanted to keep it as two different steps because it'd be annoying to have to input the password every time you run the tests. I don't think we want to clean up the log file after? Because you want to be able to see the test output after the run as well. The log file does get overwritten in every run.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

... it'd be annoying to have to input the password every time you run the tests

This is a good point.

I don't think we want to clean up the log file after? Because you want to be able to see the test output after the run as well.

My thinking was the caller could redirect to a file if they needed it kept around like you would normally when running pytest

Signed-off-by: Cody Edwards <edwards@amazon.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Jun 3, 2025

@edwards-aws edwards-aws merged commit bd39896 into OpenJobDescription:mainline Jun 3, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants