Skip to content

Commit ce00032

Browse files
committed
Server renderer
1 parent 06f417d commit ce00032

File tree

9 files changed

+117
-5
lines changed

9 files changed

+117
-5
lines changed

dist.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Crypt::Eksblowfish::Bcrypt = 0
7575
Cwd = 0
7676
DBI = 0
7777
DBIx::Class::UUIDColumns = 0
78-
DBIx::QuickDB = 0.000020
78+
DBIx::QuickDB = 0.000034
7979
Data::Dumper = 0
8080
DateTime = 0
8181
DateTime::Format::MySQL = 0

lib/App/Yath/Command/run.pm

+2
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ sub stop_plugins_and_renderers {
215215
my $exit ||= $auditor->exit_value;
216216
$_->client_finalize(settings => $settings, auditor => $auditor, exit => \$exit) for @$plugins;
217217

218+
$_->exit_hook($auditor) for reverse @$renderers;
219+
218220
return $exit || $alt_exit;
219221
}
220222

lib/App/Yath/Command/start.pm

+1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ sub become_collector {
183183
);
184184

185185
my $collector = $self->collector();
186+
186187
my $exit = $collector->process($pid);
187188

188189
remove_tree($settings->harness->workdir, {safe => 1, keep_root => 0})

lib/App/Yath/Command/test.pm

+2
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ sub become_collector {
144144

145145
$self->start_plugins_and_renderers();
146146

147+
my $collector = $self->collector;
148+
147149
my $exit = $self->SUPER::become_collector($pid);
148150

149151
return $self->stop_plugins_and_renderers($exit);

lib/App/Yath/Renderer.pm

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ sub step { }
4040
sub signal { }
4141
sub finish { }
4242

43+
sub exit_hook {}
44+
4345
sub weight { 0 }
4446

4547
1;

lib/App/Yath/Renderer/DB.pm

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ include_options(
3131
'App::Yath::Options::Yath',
3232
'App::Yath::Options::DB',
3333
'App::Yath::Options::Publish',
34-
'App::Yath::Options::WebClient',
34+
'App::Yath::Options::WebClient' => [qw/url/],
3535
);
3636

3737
sub start {
@@ -82,7 +82,7 @@ sub render_event {
8282
local $SIG{PIPE} = sub {
8383
warn "Caught SIGPIPE while writing to the database";
8484
$spipe++;
85-
$self->{+STOPPED} = 'SIGPIPE';
85+
$self->{+STOPPED} = ['SIGPIPE'];
8686
close($self->{+WRITE_PIPE});
8787
$self->{+WRITE_PIPE} = undef;
8888
};

lib/App/Yath/Renderer/Server.pm

+82
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,88 @@ package App::Yath::Renderer::Server;
22
use strict;
33
use warnings;
44

5+
our $VERSION = '2.000000';
6+
7+
use App::Yath::Schema::Util qw/schema_config_from_settings/;
8+
use App::Yath::Server;
9+
10+
use parent 'App::Yath::Renderer::DB';
11+
use Test2::Harness::Util::HashBase qw{
12+
<config
13+
<server
14+
};
15+
16+
warn "Problem 1: This prevents the test run from completing, all tests finish and it just sits there\n";
17+
warn "Problem 2: Control+c behaves badly\n";
18+
warn "We also need to make sure it waits at the end, but we cannot actually get that far...\n";
19+
20+
use Getopt::Yath;
21+
include_options(
22+
'App::Yath::Options::Yath',
23+
'App::Yath::Options::DB',
24+
'App::Yath::Options::Publish',
25+
'App::Yath::Options::WebServer',
26+
'App::Yath::Options::Server' => [qw/ephemeral/],
27+
);
28+
29+
sub start {
30+
my $self = shift;
31+
32+
my $settings = $self->settings;
33+
my $ephemeral = $settings->server->ephemeral;
34+
unless ($ephemeral) {
35+
$ephemeral = 'Auto';
36+
$settings->server->ephemeral($ephemeral);
37+
}
38+
39+
my $config = $self->{+CONFIG} //= schema_config_from_settings($settings, ephemeral => $ephemeral);
40+
41+
my $qdb_params = {
42+
single_user => 1,
43+
single_run => 1,
44+
no_upload => 1,
45+
email => undef,
46+
};
47+
48+
my $server = $self->{+SERVER} //= App::Yath::Server->new(schema_config => $config, $settings->webserver->all, qdb_params => $qdb_params);
49+
$server->start_server(no_importers => 1);
50+
51+
sleep 1;
52+
53+
$ENV{YATH_URL} = "http://" . $settings->webserver->host . ":" . $settings->webserver->port . "/";
54+
print "\nYath URL: $ENV{YATH_URL}\n\n";
55+
56+
$settings->db->config($ENV{YATH_DB_CONFIG}) if $ENV{YATH_DB_CONFIG};
57+
$settings->db->driver($ENV{YATH_DB_DRIVER}) if $ENV{YATH_DB_DRIVER};
58+
$settings->db->name($ENV{YATH_DB_NAME}) if $ENV{YATH_DB_NAME};
59+
$settings->db->user($ENV{YATH_DB_USER}) if $ENV{YATH_DB_USER};
60+
$settings->db->pass($ENV{YATH_DB_PASS}) if $ENV{YATH_DB_PASS};
61+
$settings->db->dsn($ENV{YATH_DB_DSN}) if $ENV{YATH_DB_DSN};
62+
$settings->db->host($ENV{YATH_DB_HOST}) if $ENV{YATH_DB_HOST};
63+
$settings->db->port($ENV{YATH_DB_PORT}) if $ENV{YATH_DB_PORT};
64+
$settings->db->socket($ENV{YATH_DB_SOCKET}) if $ENV{YATH_DB_SOCKET};
65+
66+
$self->SUPER::start();
67+
}
68+
69+
sub exit_hook {
70+
my $self = shift;
71+
72+
$self->SUPER::exit_hook(@_);
73+
74+
print "\nYath URL: $ENV{YATH_URL}\n\n";
75+
print "Press ENTER/RETURN to stop server and exit\n";
76+
my $x = <STDIN>;
77+
78+
delete $self->{+SERVER};
79+
delete $self->{+CONFIG};
80+
81+
return;
82+
}
83+
84+
1;
85+
86+
__END__
587
use Carp qw/croak/;
688
789
use App::Yath::Server;

lib/App/Yath/Server.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ sub start_ephemeral_db {
120120

121121
my $qdb_args;
122122
if ($schema_type eq 'Auto') {
123-
$qdb_args = {drivers => [qdb_driver('PostgreSQL'), qdb_driver('MySQL')]};
123+
$qdb_args = {drivers => [qdb_driver('PostgreSQL'), qdb_driver('MariaDB'), qdb_driver('MySQL'), qdb_driver('Percona'), qdb_driver('SQLite')]};
124124
$schema_type = undef;
125125
}
126126
else {

lib/Test2/Harness/Collector.pm

+24-1
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,8 @@ sub _process {
772772
push @$handles => [$stderr->rh, sub { $last_event = time; $self->handle_event(stderr => $stderr, $broken) }, eof => sub { $broken->{$stderr} || $stderr->eof }, name => 'stderr']
773773
unless $self->{+MERGE_OUTPUTS};
774774

775+
my %timeout_warns;
776+
775777
ipc_loop(
776778
handles => $handles,
777779
sigchild => sub { $reap->(0) },
@@ -814,8 +816,29 @@ sub _process {
814816
if (defined $exited) {
815817
for my $h (@$handles) {
816818
my ($x, $y, %params) = @$h;
817-
return 0 unless $params{eof}->();
819+
820+
my $timeout;
821+
if (my $delta = int(time - $last_event)) {
822+
$timeout = 1 if $delta > 10;
823+
824+
unless ($timeout) {
825+
if ($timeout_warns{main}) {
826+
my $countdown = int(10 - $delta);
827+
unless ($timeout_warns{$countdown}) {
828+
warn " $countdown...\n";
829+
$timeout_warns{$countdown} = 1;
830+
}
831+
}
832+
else {
833+
warn "Testing looks complete, but a filehandle is still open (Did a plugin or renderer fork without an exec?), will timeout in 10 seconds...\n";
834+
$timeout_warns{main} = 1;
835+
}
836+
}
837+
}
838+
839+
return 0 unless $params{eof}->() || $timeout;
818840
}
841+
819842
return 1 if !$auditor;
820843
return 1 if $auditor->has_plan;
821844
return 1 if $exit; # If the exit value is not true we do not wait for post-exit timeout

0 commit comments

Comments
 (0)