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

Use of Feature::Compat::Try in the test libraries #6265

Merged
merged 1 commit into from
Mar 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions t/lib/OpenQA/SeleniumTest.pm
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ our @EXPORT = qw(driver_missing check_driver_modules enable_timeout

use Carp;
use Data::Dump 'pp';
use Feature::Compat::Try;
use IPC::Run qw(start);
use Mojo::IOLoop::Server;
use Mojo::Server::Daemon;
@@ -49,7 +50,7 @@ sub disable_timeout () {

sub start_driver ($mojoport) {
# Connect to it
eval {
try {
# enforce the JSON Wire protocol (instead of using W3C WebDriver protocol)
# note: This is required with Selenium::Remote::Driver 1.36 which would now use W3C mode leading
# to errors like "unknown command: unknown command: Cannot call non W3C standard command while
@@ -97,8 +98,8 @@ sub start_driver ($mojoport) {
$_driver->set_window_size(600, 800);
$_driver->get("http://localhost:$mojoport/");

};
die $@ if ($@);
}
catch ($e) { die $e }
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering whether we should simply remove the eval/try/die completely because we just re-throw here anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can try but it can done in a different small commit later. wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, doing it in a separate commit is a good idea.


return $_driver;
}
7 changes: 5 additions & 2 deletions t/lib/OpenQA/Test/Utils.pm
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ use Mojo::IOLoop::ReadWriteProcess 'process';
use Mojo::Server::Daemon;
use Mojo::IOLoop::Server;
use Test::MockModule;
use Feature::Compat::Try;
use Time::HiRes 'sleep';

BEGIN {
@@ -595,8 +596,10 @@ sub mock_io_loop (%args) {
my $io_loop_mock = Test::MockModule->new('Mojo::IOLoop');
$io_loop_mock->redefine( # avoid forking to prevent coverage analysis from slowing down the test significantly
subprocess => sub ($io_loop, $function, $callback) {
my @result = eval { $function->() };
my $error = $@;
my @result;
my $error = '';
try { @result = $function->() }
catch ($e) { $error = $e }
$io_loop->next_tick(sub { $callback->(undef, $error, @result) });
}) if $args{subprocess};
return $io_loop_mock;