-
Notifications
You must be signed in to change notification settings - Fork 12
Automatic Browser Shutdown Update #44
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
a72e706
Created ShutdownManager
mei-kyoseva 8a72fbf
Added containsKey and containsValue methods to SingletonFactory
mei-kyoseva 7c02244
DriverService and PlaywrightService changes
mei-kyoseva 94174a1
Update ShutdownManager.java
mei-kyoseva efff035
Changes to DriverService and PlaywrightService
mei-kyoseva 9a82266
minor fixes
mei-kyoseva 21006b2
Renamed BrowserTypes enum to Browsers in Playwright module
mei-kyoseva 4183ed7
Removed "forceCloseBrowser" setting
mei-kyoseva e294604
Revert "Renamed BrowserTypes enum to Browsers in Playwright module"
mei-kyoseva e6aa3d6
Update BaseTest.java
mei-kyoseva c57e4b3
Update ShutdownManager.java
mei-kyoseva d20caa7
Update PlaywrightService.java
mei-kyoseva f97b57b
Update DriverService.java
mei-kyoseva 632b24e
Merge branch 'main' into fixes-and-refactoring
mei-kyoseva 6861fb4
Merging conflict resolved
mei-kyoseva 6d7debd
refactoring: moved retry logic into a separate method in ShadowDomSer…
mei-kyoseva 5573f2c
Update PlaywrightService.java
mei-kyoseva 00ab083
Update DriverService.java
mei-kyoseva 7bbcc7c
revert changes to testFrameworkSettings.dev.json
mei-kyoseva 5229a34
Merge branch 'main' into fixes-and-refactoring
mei-kyoseva 693aa75
Merge remote-tracking branch 'refs/remotes/origin/main' into fixes-an…
876f283
fixing formatting of PlaywrightService file
mei-kyoseva 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
75 changes: 75 additions & 0 deletions
75
bellatrix.core/src/main/java/solutions/bellatrix/core/utilities/ShutdownManager.java
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,75 @@ | ||
| /* | ||
| * Copyright 2024 Automate The Planet Ltd. | ||
| * Author: Miriam Kyoseva | ||
| * Licensed 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. | ||
| */ | ||
|
|
||
| package solutions.bellatrix.core.utilities; | ||
|
|
||
| import lombok.experimental.UtilityClass; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.concurrent.CopyOnWriteArrayList; | ||
| import java.util.concurrent.ExecutorService; | ||
| import java.util.concurrent.Executors; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| @UtilityClass | ||
| public class ShutdownManager { | ||
| private static final List<Runnable> instructions = new CopyOnWriteArrayList<>(); | ||
| private static final ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); | ||
|
|
||
| static { | ||
| Runtime.getRuntime().addShutdownHook(new Thread(ShutdownManager::runAllInstructions)); | ||
| } | ||
|
|
||
| public static void register(Runnable runnable) { | ||
| instructions.add(runnable); | ||
| } | ||
|
|
||
| private static void runAllInstructions() { | ||
| if (instructions.isEmpty()) return; | ||
|
|
||
| try { | ||
| // Submit all instructions for parallel execution | ||
| for (var instruction : instructions) { | ||
| executor.submit(() -> { | ||
| try { | ||
| instruction.run(); | ||
| } catch (Exception ex) { | ||
| DebugInformation.debugInfo(ex.getMessage()); | ||
| } | ||
| }); | ||
| } | ||
| } finally { | ||
| shutdownAndAwaitTermination(executor); | ||
| } | ||
| } | ||
|
|
||
| private static void shutdownAndAwaitTermination(ExecutorService executor) { | ||
| executor.shutdown(); // Disable new tasks from being submitted | ||
| try { | ||
| // Wait a while for existing tasks to terminate | ||
| if (!executor.awaitTermination(60, TimeUnit.SECONDS)) { | ||
| executor.shutdownNow(); // Cancel currently executing tasks | ||
| // Wait a while for tasks to respond to being cancelled | ||
| if (!executor.awaitTermination(60, TimeUnit.SECONDS)) { | ||
| System.err.println("Executor did not terminate."); | ||
| } | ||
| } | ||
| } catch (InterruptedException ie) { | ||
| // (Re-)Cancel if current thread also interrupted | ||
| executor.shutdownNow(); | ||
| // Preserve interrupt status | ||
| Thread.currentThread().interrupt(); | ||
| } | ||
| } | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.