GithubHelp home page GithubHelp logo

opensuse / mojo-ioloop-readwriteprocess Goto Github PK

View Code? Open in Web Editor NEW
10.0 12.0 13.0 596 KB

Execute external programs or internal code blocks as separate process

License: Other

Perl 98.89% Shell 1.11%
mojo ioloop eventemitter subreaper cgroups process-manager hacktoberfest

mojo-ioloop-readwriteprocess's Introduction

Coverage Status Actions Status

NAME

Mojo::IOLoop::ReadWriteProcess - Execute external programs or internal code blocks as separate process.

SYNOPSIS

use Mojo::IOLoop::ReadWriteProcess;

# Code fork
my $process = Mojo::IOLoop::ReadWriteProcess->new(sub { print "Hello\n" });
$process->start();
print "Running\n" if $process->is_running();
$process->getline(); # Will return "Hello\n"
$process->pid(); # Process id
$process->stop();
$process->wait_stop(); # if you intend to wait its lifespan

# Methods can be chained, thus this is valid:
use Mojo::IOLoop::ReadWriteProcess qw(process);
my $output = process( sub { print "Hello\n" } )->start()->wait_stop->getline;

# Handles seamelessy also external processes:
my $process = process(execute=> '/path/to/bin' )->args([qw(foo bar baz)]);
$process->start();
my $line_output = $process->getline();
my $pid = $process->pid();
$process->stop();
my @errors = $process->error;

# Get process return value
$process = process( sub { return "256"; } )->start()->wait_stop;
# We need to stop it to retrieve the exit status
my $return = $process->return_status;

# We can access directly to handlers from the object:
my $stdout = $process->read_stream;
my $stdin = $process->write_stream;
my $stderr = $process->error_stream;

# So this works:
print $stdin "foo bar\n";
my @lines = <$stdout>;

# There is also an alternative channel of communication (just for forked processes):
my $channel_in = $process->channel_in; # write to the child process
my $channel_out = $process->channel_out; # read from the child process
$process->channel_write("PING"); # convenience function

DESCRIPTION

Mojo::IOLoop::ReadWriteProcess is yet another process manager.

EVENTS

Mojo::IOLoop::ReadWriteProcess inherits all events from Mojo::EventEmitter and can emit the following new ones.

start

$process->on(start => sub {
  my ($process) = @_;
  $process->is_running();
});

Emitted when the process starts.

stop

$process->on(stop => sub {
  my ($process) = @_;
  $process->restart();
});

Emitted when the process stops.

process_error

$process->on(process_error => sub {
  my ($e) = @_;
  my @errors = @{$e};
});

Emitted when the process produce errors.

process_stuck

$process->on(process_stuck => sub {
  my ($self) = @_;
  ...
});

Emitted when blocking_stop is set and all attempts for killing the process in max_kill_attempts have been exhausted. The event is emitted before attempting to kill it with SIGKILL and becoming blocking.

SIG_CHLD

$process->on(SIG_CHLD => sub {
  my ($self) = @_;
  ...
});

Emitted when we receive SIG_CHLD.

SIG_TERM

$process->on(SIG_TERM => sub {
  my ($self) = @_;
  ...
});

Emitted when the child forked process receives SIG_TERM, before exiting.

collected

$process->on(collected => sub {
  my ($self) = @_;
  ...
});

Emitted right after status collection.

collect_status

$process->on(collect_status => sub {
  my ($self) = @_;
  ...
});

Emitted when on child process waitpid. It is used internally to get the child process status. Note: events attached to it are wiped when process has been stopped.

ATTRIBUTES

Mojo::IOLoop::ReadWriteProcess inherits all attributes from Mojo::EventEmitter and implements the following new ones.

execute

use Mojo::IOLoop::ReadWriteProcess;
my $process = Mojo::IOLoop::ReadWriteProcess->new(execute => "/usr/bin/perl");
$process->start();
$process->on( stop => sub { print "Process: ".(+shift()->pid)." finished"; } );
$process->stop();

execute should contain the external program that you wish to run.

code

use Mojo::IOLoop::ReadWriteProcess;
my $process = Mojo::IOLoop::ReadWriteProcess->new(code => sub { print "Hello" } );
$process->start();
$process->on( stop => sub { print "Process: ".(+shift()->pid)." finished"; } );
$process->stop();

It represent the code you want to run in background.

You do not need to specify code, it is implied if no arguments is given.

my $process = Mojo::IOLoop::ReadWriteProcess->new(sub { print "Hello" });
$process->start();
$process->on( stop => sub { print "Process: ".(+shift()->pid)." finished"; } );
$process->stop();

args

use Mojo::IOLoop::ReadWriteProcess;
my $process = Mojo::IOLoop::ReadWriteProcess->new(code => sub { print "Hello ".$_[1] }, args => "User" );
$process->start();
$process->on( stop => sub { print "Process: ".(+shift()->pid)." finished"; } );
$process->stop();

# The process will print "Hello User"

Arguments pass to the external binary or the code block. Use arrayref to pass many.

blocking_stop

use Mojo::IOLoop::ReadWriteProcess;
my $process = Mojo::IOLoop::ReadWriteProcess->new(code => sub { print "Hello" }, blocking_stop => 1 );
$process->start();
$process->on( stop => sub { print "Process: ".(+shift()->pid)." finished"; } );
$process->stop(); # Will wait indefinitely until the process is stopped

Set it to 1 if you want to do blocking stop of the process.

channels

use Mojo::IOLoop::ReadWriteProcess;
my $process = Mojo::IOLoop::ReadWriteProcess->new(code => sub { print "Hello" }, channels => 0 );
$process->start();
$process->on( stop => sub { print "Process: ".(+shift()->pid)." finished"; } );
$process->stop(); # Will wait indefinitely until the process is stopped

Set it to 0 if you want to disable internal channels.

session

use Mojo::IOLoop::ReadWriteProcess;
my $process = Mojo::IOLoop::ReadWriteProcess->new(sub { print "Hello" });
my $session = $process->session;
$session->enable_subreaper;

Returns the current Mojo::IOLoop::ReadWriteProcess::Session singleton.

subreaper

use Mojo::IOLoop::ReadWriteProcess;
my $process = Mojo::IOLoop::ReadWriteProcess->new(code => sub { print "Hello ".$_[1] }, args => "User" );
$process->subreaper(1)->start();
$process->on( stop => sub { shift()->disable_subreaper } );
$process->stop();

# The process will print "Hello User"

Mark the current process (not the child) as subreaper on start. It's on invoker behalf to disable subreaper when process stops, as it marks the current process and not the child.

ioloop

my $loop    = $process->ioloop;
$subprocess = $process->ioloop(Mojo::IOLoop->new);

Event loop object to control, defaults to the global Mojo::IOLoop singleton.

max_kill_attempts

use Mojo::IOLoop::ReadWriteProcess;
my $process = Mojo::IOLoop::ReadWriteProcess->new(code => sub { print "Hello" }, max_kill_attempts => 50 );
$process->start();
$process->on( stop => sub { print "Process: ".(+shift()->pid)." finished"; } );
$process->stop(); # It will attempt to send SIGTERM 50 times.

Defaults to 5, is the number of attempts before bailing out.

It can be used with blocking_stop, so if the number of attempts are exhausted, a SIGKILL and waitpid will be tried at the end.

kill_whole_group

use Mojo::IOLoop::ReadWriteProcess;
my $process = Mojo::IOLoop::ReadWriteProcess->new(code => sub { setpgrp(0, 0); exec(...); }, kill_whole_group => 1 );
$process->start();
$process->send_signal(...); # Will skip the usual check whether $process->pid is running
$process->stop();           # Kills the entire process group and waits for all processes in the group to finish

Defaults to 0, whether to send signals (e.g. to stop) to the entire process group.

This is useful when the sub process creates further sub processes and creates a new process group as shown in the example. In this case it might be useful to take care of the entire process group when stopping and wait for every process in the group to finish.

collect_status

Defaults to 1, If enabled it will automatically collect the status of the children process. Disable it in case you want to manage your process child directly, and do not want to rely on automatic collect status. If you won't overwrite your SIGCHLD handler, the SIG_CHLD event will be still emitted.

serialize

Defaults to 0, If enabled data returned from forked process will be serialized with Storable.

kill_sleeptime

Defaults to 1, it's the seconds to wait before attempting SIGKILL when blocking_stop is set to 1.

separate_err

Defaults to 1, it will create a separate channel to intercept process STDERR, otherwise it will be redirected to STDOUT.

verbose

Defaults to 1, it indicates message verbosity.

set_pipes

Defaults to 1, If enabled, additional pipes for process communication are automatically set up.

internal_pipes

Defaults to 1, If enabled, additional pipes for retreiving process return and errors are set up. Note: If you disable that, the only information provided by the process will be the exit_status.

autoflush

Defaults to 1, If enabled autoflush of handlers is enabled automatically.

error

Returns a Mojo::Collection of errors. Note: errors that can be captured only at the end of the process

METHODS

Mojo::IOLoop::ReadWriteProcess inherits all methods from Mojo::EventEmitter and implements the following new ones.

start()

use Mojo::IOLoop::ReadWriteProcess qw(process);
my $p = process(sub {
                      print STDERR "Boo\n"
                  } )->start;

Starts the process

stop()

use Mojo::IOLoop::ReadWriteProcess qw(process);
my $p = process( execute => "/path/to/bin" )->start->stop;

Stop the process. Unless you use wait_stop(), it will attempt to kill the process without waiting the process to finish. By defaults it send SIGTERM to the child. You can change that by defining the internal attribute _default_kill_signal. Note, if you want to be *sure* that the process gets killed, you can enable the blocking_stop attribute, that will attempt to send SIGKILL after max_kill_attempts is reached.

restart()

use Mojo::IOLoop::ReadWriteProcess qw(process);
my $p = process( execute => "/path/to/bin" )->restart;

It restarts the process if stopped, or if already running, it stops it first.

is_running()

use Mojo::IOLoop::ReadWriteProcess qw(process);
my $p = process( execute => "/path/to/bin" )->start;
$p->is_running;

Boolean, it inspect if the process is currently running or not.

exit_status()

use Mojo::IOLoop::ReadWriteProcess qw(process);
my $p = process( execute => "/path/to/bin" )->start;

$p->wait_stop->exit_status;

Inspect the process exit status, it does the shifting magic, to access to the real value call _status().

return_status()

use Mojo::IOLoop::ReadWriteProcess qw(process);
my $p = process( sub { return 42 } )->start;

my $s = $p->wait_stop->return_status; # 42

Inspect the codeblock return.

enable_subreaper()

use Mojo::IOLoop::ReadWriteProcess qw(process);
my $p = process()->enable_subreaper;

Mark the current process (not the child) as subreaper. This is used typically if you want to mark further children as subreapers inside other forks.

my $master_p = process(
  sub {
    my $p = shift;
    $p->enable_subreaper;

    process(sub { sleep 4; exit 1 })->start();
    process(
      sub {
        sleep 4;
        process(sub { sleep 1; })->start();
      })->start();
    process(sub { sleep 4; exit 0 })->start();
    process(sub { sleep 4; die })->start();
    my $manager
      = process(sub { sleep 2 })->subreaper(1)->start();
    sleep 1 for (0 .. 10);
    $manager->stop;
    return $manager->session->all->size;
  });

$master_p->subreaper(1);

$master_p->on(collected => sub { $status++ });

# On start we setup the current process as subreaper
# So it's up on us to disable it after process is done.
$master_p->on(stop => sub { shift()->disable_subreaper });
$master_p->start();

disable_subreaper()

use Mojo::IOLoop::ReadWriteProcess qw(process);
my $p = process()->disable_subreaper;

Unset the current process (not the child) as subreaper.

prctl()

use Mojo::IOLoop::ReadWriteProcess qw(process);
my $p = process();
$p->prctl($option, $arg2, $arg3, $arg4, $arg5);

Internal function to execute and wrap the prctl syscall, accepts the same arguments as prctl.

diag()

use Mojo::IOLoop::ReadWriteProcess qw(process);
my $p = process(sub { print "Hello\n" });
$p->on( stop => sub { shift->diag("Done!") } );
$p->start->wait_stop;

Internal function to print information to STDERR if verbose attribute is set or either DEBUG mode enabled. You can use it if you wish to display information on the process status.

to_ioloop()

use Mojo::IOLoop::ReadWriteProcess qw(process);

my $p = process(sub {  print "Hello from first process\n"; sleep 1 });

$p->start(); # Start and sets the handlers
my $stream = $p->to_ioloop; # Get the stream and demand to IOLoop
my $output;

# Hook on Mojo::IOLoop::Stream events
$stream->on(read => sub { $output .= pop;  $p->is_running ...  });

Mojo::IOLoop->singleton->start() unless Mojo::IOLoop->singleton->is_running;

Returns a Mojo::IOLoop::Stream object and demand the wait operation to Mojo::IOLoop. It needs set_pipes enabled. Default IOLoop can be overridden in ioloop().

wait()

use Mojo::IOLoop::ReadWriteProcess qw(process);
my $p = process(sub { print "Hello\n" })->wait;
# ... here now you can mangle $p handlers and such

Waits until the process finishes, but does not performs cleanup operations (until stop is called).

wait_stop()

use Mojo::IOLoop::ReadWriteProcess qw(process);
my $p = process(sub { print "Hello\n" })->start->wait_stop;
# $p is not running anymore, and all possible events have been granted to be emitted.

Waits until the process finishes, and perform cleanup operations.

errored()

use Mojo::IOLoop::ReadWriteProcess qw(process);
my $p = process(sub { die "Nooo" })->start->wait_stop;
$p->errored; # will return "1"

Returns a boolean indicating if the process had errors or not.

write_pidfile()

use Mojo::IOLoop::ReadWriteProcess qw(process);
my $p = process(sub { die "Nooo" } );
$p->pidfile("foobar");
$p->start();
$p->write_pidfile();

Forces writing PID of process to specified pidfile in the attributes of the object. Useful only if the process have been already started, otherwise if a pidfile it's supplied as attribute, it will be done automatically.

write_stdin()

use Mojo::IOLoop::ReadWriteProcess qw(process);
my $p = process(sub { my $a = <STDIN>; print STDERR "Hello my name is $a\n"; } )->start;
$p->write_stdin("Larry");
$p->read_stderr; # process STDERR will contain: "Hello my name is Larry\n"

Write data to process STDIN.

write_channel()

use Mojo::IOLoop::ReadWriteProcess qw(process);
my $p = process(sub {
                      my $self = shift;
                      my $parent_output = $self->channel_out;
                      my $parent_input  = $self->channel_in;

                      while(defined(my $line = <$parent_input>)) {
                        print $parent_output "PONG\n" if $line =~ /PING/i;
                      }
                  } )->start;
$p->write_channel("PING");
my $out = $p->read_channel;
# $out is PONG
my $child_output = $p->channel_out;
while(defined(my $line = <$child_output>)) {
    print "Process is replying back with $line!\n";
    $p->write_channel("PING");
}

Write data to process channel. Note, it's not STDIN, neither STDOUT, it's a complete separate channel dedicated to parent-child communication. In the parent process, you can access to the same pipes (but from the opposite direction):

my $child_output = $self->channel_out;
my $child_input  = $self->channel_in;

read_stdout()

use Mojo::IOLoop::ReadWriteProcess qw(process);
my $p = process(sub {
                      print "Boo\n"
                  } )->start;
$p->read_stdout;

Gets a single line from process STDOUT.

read_channel()

use Mojo::IOLoop::ReadWriteProcess qw(process);
my $p = process(sub {
                      my $self = shift;
                      my $parent_output = $self->channel_out;
                      my $parent_input  = $self->channel_in;

                      print $parent_output "PONG\n";
                  } )->start;
$p->read_channel;

Gets a single line from process channel.

read_stderr()

use Mojo::IOLoop::ReadWriteProcess qw(process);
my $p = process(sub {
                      print STDERR "Boo\n"
                  } )->start;
$p->read_stderr;

Gets a single line from process STDERR.

read_all_stdout()

use Mojo::IOLoop::ReadWriteProcess qw(process);
my $p = process(sub {
                      print "Boo\n"
                  } )->start;
$p->read_all_stdout;

Gets all the STDOUT output of the process.

read_all_channel()

use Mojo::IOLoop::ReadWriteProcess qw(process);
my $p = process(sub {
                      shift->channel_out->write("Ping")
                  } )->start;
$p->read_all_channel;

Gets all the channel output of the process.

read_all_stderr()

use Mojo::IOLoop::ReadWriteProcess qw(process);
my $p = process(sub {
                      print STDERR "Boo\n"
                  } )->start;
$p->read_all_stderr;

Gets all the STDERR output of the process.

send_signal()

use Mojo::IOLoop::ReadWriteProcess qw(process);
use POSIX;
my $p = process( execute => "/path/to/bin" )->start;

$p->send_signal(POSIX::SIGKILL);

Send a signal to the process

EXPORTS

parallel()

use Mojo::IOLoop::ReadWriteProcess qw(parallel);
my $pool = parallel sub { print "Hello\n" } => 5;
$pool->start();
$pool->on( stop => sub { print "Process: ".(+shift()->pid)." finished"; } );
$pool->stop();

Returns a Mojo::IOLoop::ReadWriteProcess::Pool object that represent a group of processes.

It accepts the same arguments as Mojo::IOLoop::ReadWriteProcess, and the last one represent the number of processes to generate.

batch()

use Mojo::IOLoop::ReadWriteProcess qw(batch);
my $pool = batch;
$pool->add(sub { print "Hello\n" });
$pool->on(stop => sub { shift->_diag("Done!") })->start->wait_stop;

Returns a Mojo::IOLoop::ReadWriteProcess::Pool object generated from supplied arguments. It accepts as input the same parameter of Mojo::IOLoop::ReadWriteProcess::Pool constructor ( see parallel() ).

process()

use Mojo::IOLoop::ReadWriteProcess qw(process);
my $p = process sub { print "Hello\n" };
$p->start()->wait_stop;

or even:

process(sub { print "Hello\n" })->start->wait_stop;

Returns a Mojo::IOLoop::ReadWriteProcess object that represent a process.

It accepts the same arguments as Mojo::IOLoop::ReadWriteProcess.

queue()

use Mojo::IOLoop::ReadWriteProcess qw(queue);
my $q = queue;
$q->add(sub { return 42 } );
$q->consume;

Returns a Mojo::IOLoop::ReadWriteProcess::Queue object that represent a queue.

DEBUGGING

You can set the MOJO_EVENTEMITTER_DEBUG environment variable to get some advanced diagnostics information printed to STDERR.

MOJO_EVENTEMITTER_DEBUG=1

Also, you can set MOJO_PROCESS_DEBUG environment variable to get diagnostics about the process execution.

MOJO_PROCESS_DEBUG=1

LICENSE

Copyright (C) Ettore Di Giacinto.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

Ettore Di Giacinto [email protected]

mojo-ioloop-readwriteprocess's People

Contributors

adamwill avatar cfconrad avatar foursixnine avatar gregoa avatar knowledgejunkie avatar kraih avatar manwar avatar martchus avatar mudler avatar okurz avatar perlpunk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mojo-ioloop-readwriteprocess's Issues

os-autoinst test failures with v0.31

Since version 0.31 we are seeing the following test failures"

[  212s] 3: 
[  212s] 3: #   Failed test 'exit logged'
[  212s] 3: #   at ./29-backend-driver.t line 31.
[  212s] 3: # STDOUT & STDERR:
[  212s] 3: # [37m[2021-12-06T17:11:16.953486Z] [debug] received magic close
[  212s] 3: # [0m
[  212s] 3: # don't match:
[  212s] 3: # (?^u:backend.*exited)
[  212s] 3: # as expected
[  212s] 3: [37m[2021-12-06T17:11:17.057808Z] [debug] backend process exited: 72057594037927935
[  212s] 3: [0m# Looks like you failed 1 test of 12.
[  212s] 3: [17:11:17] ./29-backend-driver.t .................... 
[  212s] 3: Dubious, test returned 1 (wstat 256, 0x100)
[  212s] 3: Failed 1/12 subtests 

Also we see this:

Can't open out pipe for reading Interrupted system call at ./10-virtio_terminal.t line 44.

https://github.com/os-autoinst/os-autoinst/blob/master/t/29-backend-driver.t#L31

More details: https://progress.opensuse.org/issues/103422#note-20

t/01_run.t fails with: Error: Failed test 'sigchld_handler.pl exit with 0' got: '255' expected: '0'

= GitHub Actions Report =
Notice: See the full report in: https://github.com/openSUSE/Mojo-IOLoop-ReadWriteProcess/actions/runs/7101104914
Error: Failed test 'sigchld_handler.pl exit with 0'
--- CAPTURED CONTEXT ---
got: '255'
expected: '0'
--- END OF CONTEXT ---
Error: Failed test 'SIG_CHLD handler was executed'
--- CAPTURED CONTEXT ---
''
doesn't match '(?^:SIG_CHLD)'
--- END OF CONTEXT ---
Error: Failed test 'SIG_CHLD handler in spawned process'

Proposal: Move to https://github.com/openSUSE

We see this project being actively used by e.g. the os-autoinst project , there are packages within openSUSE and there is active review and contribution work by multiple contributors (and less the original author). I suggest to move the project to the openSUSE scope in github. If you agree then I suggest you (any owner of the project) transfer the ownership in the github settings. Someone in the openSUSE project (not sure if I can do this) should be able to accept the request.

sporadic errors in test suite, e.g. t/07_autodetect.t , t/12_mocked_container.t , t/04_queues.t , 05_serialize.t

Observation

https://build.opensuse.org/package/live_build_log/devel:openQA:Leap:15.1/perl-Mojo-IOLoop-ReadWriteProcess/openSUSE_Leap_15.1/x86_64 shows

[   97s] TEST error print
[   97s] TEST error print
[   97s] t/01_run.t ............... ok
[  108s] t/02_parallel.t .......... ok
[  109s] Can't use an undefined value as filehandle reference at lib/Mojo/IOLoop/ReadWriteProcess.pm line 298.
[  126s] t/03_func.t .............. ok
[  127s] t/04_queues.t ............ ok
[  127s] t/05_serialize.t ......... ok
[  131s] t/06_events.t ............ ok
[  191s] 
[  191s]     #   Failed test 'collect_status fired 8 times'
[  191s]     #   at t/07_autodetect.t line 411.
[  191s]     #          got: undef
[  191s]     #     expected: '1'
[  191s] 
[  191s]     #   Failed test 'new_subprocess fired 7 times'
[  191s]     #   at t/07_autodetect.t line 412.
[  191s]     #          got: '9'
[  191s]     #     expected: '8'
[  191s] 
[  191s]     #   Failed test 'detection works'
[  191s]     #   at t/07_autodetect.t line 414.
[  191s]     #          got: '9'
[  191s]     #     expected: '8'
[  191s]     # bless( {
[  191s]     #   '_status' => -1,
[  191s]     #   'args' => [],
[  191s]     #   'error' => bless( [], 'Mojo::Collection' ),
[  191s]     #   'error_stream' => bless( \*Symbol::GEN122, 'IO::Handle' ),
[  191s]     #   'events' => {},
[  191s]     #   'execute' => '/home/abuild/rpmbuild/BUILD/Mojo-IOLoop-ReadWriteProcess-0.28/t/data/subreaper/roulette.sh',
[  191s]     #   'process_id' => 1744,
[  191s]     #   'read_stream' => bless( \*Symbol::GEN120, 'IO::Handle' ),
[  191s]     #   'separate_err' => 1,
[  191s]     #   'session' => bless( {
[  191s]     #     'collect_status' => 1,
[  191s]     #     'events' => {
[  191s]     #       'collected' => [
[  191s]     #         sub { "DUMMY" }
[  191s]     #       ],
[  191s]     #       'collected_orphan' => [
[  191s]     #         sub { "DUMMY" }
[  191s]     #       ]
[  191s]     #     },
[  191s]     #     'handler' => undef,
[  191s]     #     'orphans' => {
[  191s]     #       '1744' => bless( {
[  191s]     #         '_status' => 256,
[  191s]     #         'process_id' => 1744
[  191s]     #       }, 'Mojo::IOLoop::ReadWriteProcess' ),
[  191s]     #       '1748' => bless( {
[  191s]     #         '_status' => 256,
[  191s]     #         'process_id' => 1748
[  191s]     #       }, 'Mojo::IOLoop::ReadWriteProcess' ),
[  191s]     #       '1749' => bless( {
[  191s]     #         '_status' => 256,
[  191s]     #         'process_id' => 1749
[  191s]     #       }, 'Mojo::IOLoop::ReadWriteProcess' ),
[  191s]     #       '1755' => bless( {
[  191s]     #         '_status' => 256,
[  191s]     #         'process_id' => 1755
[  191s]     #       }, 'Mojo::IOLoop::ReadWriteProcess' ),
[  191s]     #       '1756' => bless( {
[  191s]     #         '_status' => 256,
[  191s]     #         'process_id' => 1756
[  191s]     #       }, 'Mojo::IOLoop::ReadWriteProcess' ),
[  191s]     #       '1762' => bless( {
[  191s]     #         '_status' => 0,
[  191s]     #         'process_id' => 1762
[  191s]     #       }, 'Mojo::IOLoop::ReadWriteProcess' ),
[  191s]     #       '1763' => bless( {
[  191s]     #         '_status' => 0,
[  191s]     #         'process_id' => 1763
[  191s]     #       }, 'Mojo::IOLoop::ReadWriteProcess' ),
[  191s]     #       '1773' => bless( {
[  191s]     #         '_status' => 0,
[  191s]     #         'process_id' => 1773
[  191s]     #       }, 'Mojo::IOLoop::ReadWriteProcess' ),
[  191s]     #       '1774' => bless( {
[  191s]     #         '_status' => 0,
[  191s]     #         'process_id' => 1774
[  191s]     #       }, 'Mojo::IOLoop::ReadWriteProcess' )
[  191s]     #     },
[  191s]     #     'process_table' => {
[  191s]     #       '1744' => \$VAR1
[  191s]     #     },
[  191s]     #     'subreaper' => 1
[  191s]     #   }, 'Mojo::IOLoop::ReadWriteProcess::Session' ),
[  191s]     #   'set_pipes' => 1,
[  191s]     #   'subreaper' => 1,
[  191s]     #   'write_stream' => bless( \*Symbol::GEN121, 'IO::Handle' )
[  191s]     # }, 'Mojo::IOLoop::ReadWriteProcess' )
[  191s]     # Looks like you failed 3 tests of 4.
[  191s] 
[  191s] #   Failed test 'subreaper_bash_roulette'
[  191s] #   at t/07_autodetect.t line 418.
[  191s] 0 at t/07_autodetect.t line 414.
[  191s] # Tests were run but no plan was declared and done_testing() was not seen.
[  191s] # Looks like your test exited with 255 just after 7.
[  191s] t/07_autodetect.t ........ 
[  191s] Dubious, test returned 255 (wstat 65280, 0xff00)
[  191s] Failed 1/7 subtests 
[  191s] 	(less 2 skipped subtests: 4 okay)
[  193s] t/08_ioloop.t ............ ok
[  194s] t/09_session.t ........... ok
[  195s] t/10_cgroupv1.t .......... ok
[  196s] t/10_cgroupv2.t .......... ok
[  197s] t/11_containers.t ........ skipped: This test works only if you have cgroups permissions
[  255s] t/12_mocked_container.t .. ok
[  256s] t/13_shared.t ............ skipped: Skipped unless TEST_SHARED is set
[  256s] 
[  256s] Test Summary Report
[  256s] -------------------
[  256s] t/07_autodetect.t      (Wstat: 65280 Tests: 7 Failed: 1)
[  256s]   Failed test:  7
[  256s]   Non-zero exit status: 255
[  256s]   Parse errors: No plan found in TAP output
[  256s] Files=15, Tests=62, 162 wallclock secs ( 0.25 usr  0.15 sys + 11.89 cusr  2.20 csys = 14.49 CPU)
[  256s] Result: FAIL
[  256s] Failed 1/15 test programs. 1/62 subtests failed.

so unhandled output in t/01_run.t, perl warning "Can't use an undefined value as filehandle reference at lib/Mojo/IOLoop/ReadWriteProcess.pm line 298." in t/03_func.t and errors in t/07_autodetect.t

Then in https://build.opensuse.org/package/live_build_log/devel:openQA:Leap:15.2/perl-Mojo-IOLoop-ReadWriteProcess/openSUSE_Leap_15.2/aarch64

[  187s] t/11_containers.t ........ skipped: This test works only if you have cgroups permissions
[  211s] 
[  211s]     #   Failed test 'procs interface contains the added pids'
[  211s]     #   at t/12_mocked_container.t line 37.
[  211s]     #          got: ''
[  211s]     #     expected: '1785
[  211s]     # '
[  211s]     # 1785
[  244s]     # Looks like you failed 1 test of 43.
[  244s] 
[  244s] #   Failed test 'container_3'
[  244s] #   at t/12_mocked_container.t line 258.
[  244s] # Looks like you failed 1 test of 3.
[  244s] t/12_mocked_container.t .. 
[  244s] Dubious, test returned 1 (wstat 256, 0x100)
[  244s] Failed 1/3 subtests

and in
https://build.opensuse.org/package/live_build_log/devel:openQA:Leap:15.2/perl-Mojo-IOLoop-ReadWriteProcess/openSUSE_Leap_15.2/x86_64

[   70s] t/03_func.t .............. ok
[   71s] t/04_queues.t ............ ok
[ 3679s] qemu-system-x86_64: terminating on signal 15 from pid 18026 ()


Job seems to be stuck here, killed. (after 3600 seconds of inactivity)

so stuck in tests.

https://build.opensuse.org/package/live_build_log/devel:openQA:Leap:15.2/perl-Mojo-IOLoop-ReadWriteProcess/openSUSE_Leap_15.2/ppc64le shows again:

[  119s] t/04_queues.t ............ ok
[ 3725s] qemu-system-ppc64: terminating on signal 15 from pid 27286 (<unknown process>)

Not sure if that means that t/04_queues.t is stuck after it returned "ok" or if the next test module "05_serialize.t" starts, gets stuck and never finishes.

Impact

I have not observed an impact going further than these tests failing, e.g. no visible impact on openQA behaviour where we use Mojo-IOLoop-ReadWriteProcess heavily.

Workaround

I will propose to skip the according tests in OBS for now.

tests hang on Windows

03_func.t:

# Subtest: _new_err
    ok 1
    ok 2
    1..2
ok 1 - _new_err
# Subtest: write_pidfile
    ok 1
    1..1
ok 2 - write_pidfile
# Subtest: _fork
Can't use an undefined value as filehandle reference at lib/Mojo/IOLoop/ReadWriteProcess.pm line 229.
(hangs)

If your module cannot work on Windows at all, you can die in Makefile.PL/Build.PL. See http://wiki.cpantesters.org/wiki/CPANAuthorNotes for how to do this.

The tests in t/10_cgroupv* use invalid paths

The tests in t/10_cgroupv* use invalid paths. This wasn't a huge problem until Mojolicious 8.23 was released. In that version, Mojo::File was modified not to allow undefined values in paths.

This breaks the tests in t/10_cgroupv*.

Process execution sometimes fails on ppc64le and s390x

I'm working on updating Fedora's openQA packages to the latest git versions. os-autoinst was recently improved to include exit codes in output when running commands via run_diag (which uses ReadWriteProcess's process to do the heavy lifting), and a test for this was added.

In test builds, this test is quite often failing on ppc64le or s390x arch, because the command - a simple echo foo - exits with 1 instead of the expected 0:

2:     #   Failed test 'Exit code appear in log'
2:     #   at ./13-osutils.t line 167.
2:     # STDERR:
2:     # [2021-11-26T19:00:09.618335Z] [debug] running `echo foo`
2:     # [2021-11-26T19:00:09.619749Z] [debug] Command `echo foo` terminated with 1
2:     #   foo
2:     # 
2:     # doesn't match:
2:     # (?^u:terminated with 0)
2:     # as expected
2:     # Looks like you failed 1 test of 10.
2: 
2: #   Failed test 'run_diag'
2: #   at ./13-osutils.t line 190.
2: # Looks like you failed 1 test of 9.

I don't know why this is happening, but it seems likely it's an issue in RWP, I don't see how the code on the os-autoinst side could be causing it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.