-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
[rb] Release a stopped service instead of holding it until the process exits #17894
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
Open
ikraamg
wants to merge
3
commits into
SeleniumHQ:trunk
Choose a base branch
from
ikraamg:fix/release-stopped-services-at-exit
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+159
−1
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
rb/spec/unit/selenium/webdriver/common/service_manager_spec.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Licensed to the Software Freedom Conservancy (SFC) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The SFC licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| require File.expand_path('../spec_helper', __dir__) | ||
|
|
||
| module Selenium | ||
| module WebDriver | ||
| describe ServiceManager do | ||
| subject(:manager) { build_manager } | ||
|
|
||
| let(:running) { described_class.instance_variable_get(:@running) } | ||
|
|
||
| # The service itself is never launched; only the bookkeeping around it is under test. | ||
| def build_manager(port: 4444) | ||
| config = instance_double(Service, executable_path: '/path/to/service', port: port, | ||
| log: nil, args: [], shutdown_supported: true) | ||
| described_class.new(config).tap do |service_manager| | ||
| allow(service_manager).to receive_messages(socket_lock: yielding_lock, find_free_port: nil, | ||
|
Comment on lines
+31
to
+34
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. Rspec mocks in new spec The new unit spec relies on RSpec mocking (instance_double, allow(...).to receive_messages) rather than real or contract-driven integrations, which risks tests diverging from real interfaces over time. Agent Prompt
|
||
| start_process: nil, connect_until_stable: nil, | ||
| stop_process: nil) | ||
| end | ||
| end | ||
|
|
||
| def yielding_lock | ||
| instance_double(SocketLock).tap { |lock| allow(lock).to receive(:locked).and_yield } | ||
| end | ||
|
|
||
| # The tracking list and the pid that armed the exit hook outlive an example, so a | ||
| # later one would otherwise see the hook as already armed. | ||
| before do | ||
| described_class.instance_variable_set(:@running, []) | ||
| described_class.instance_variable_set(:@exit_hook_pid, nil) | ||
| end | ||
|
|
||
| after { described_class.stop_running } | ||
|
|
||
| describe '.track' do | ||
| it 'holds a started service so it can be stopped at exit' do | ||
| manager.start | ||
|
|
||
| expect(running).to include(manager) | ||
| end | ||
|
|
||
| it 'registers a single exit hook however many services start' do | ||
| allow(Platform).to receive(:exit_hook) | ||
|
|
||
| 2.times { build_manager.start } | ||
|
|
||
| expect(Platform).to have_received(:exit_hook).exactly(:once) | ||
| end | ||
| end | ||
|
|
||
| describe '.untrack' do | ||
| it 'releases a service once it is stopped' do | ||
| manager.start | ||
| manager.stop | ||
|
|
||
| expect(running).not_to include(manager) | ||
| end | ||
| end | ||
|
|
||
| describe '.stop_running' do | ||
| it 'stops a service that is still running' do | ||
| manager.start | ||
|
|
||
| described_class.stop_running | ||
|
|
||
| expect(manager).to have_received(:stop_process) | ||
| end | ||
|
|
||
| it 'leaves a service inherited through a fork to the parent' do | ||
| manager.start | ||
| described_class.instance_variable_set(:@exit_hook_pid, Process.pid - 1) | ||
|
|
||
| described_class.stop_running | ||
|
|
||
| expect(manager).not_to have_received(:stop_process) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.