[Jifty-commit] r6952 - in jifty/trunk/t/TestApp-RestartServer: . bin etc t var
Jifty commits
jifty-commit at lists.jifty.org
Thu May 7 02:47:15 EDT 2009
Author: sunnavy
Date: Thu May 7 02:47:15 2009
New Revision: 6952
Added:
jifty/trunk/t/TestApp-RestartServer/
jifty/trunk/t/TestApp-RestartServer/bin/
jifty/trunk/t/TestApp-RestartServer/bin/jifty
jifty/trunk/t/TestApp-RestartServer/etc/
jifty/trunk/t/TestApp-RestartServer/etc/config.yml
jifty/trunk/t/TestApp-RestartServer/t/
jifty/trunk/t/TestApp-RestartServer/t/restart.t
jifty/trunk/t/TestApp-RestartServer/var/
jifty/trunk/t/TestApp-RestartServer/var/mason/
Log:
add restart server test
Added: jifty/trunk/t/TestApp-RestartServer/bin/jifty
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp-RestartServer/bin/jifty Thu May 7 02:47:15 2009
@@ -0,0 +1,11 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+use File::Basename qw(dirname);
+use UNIVERSAL::require;
+
+use Jifty;
+use Jifty::Script;
+
+local $SIG{INT} = sub { warn "Stopped\n"; exit; };
+Jifty::Script->dispatch();
Added: jifty/trunk/t/TestApp-RestartServer/etc/config.yml
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp-RestartServer/etc/config.yml Thu May 7 02:47:15 2009
@@ -0,0 +1,47 @@
+---
+framework:
+ AdminMode: 1
+ ApplicationClass: TestApp::RestartServer
+ ApplicationName: TestApp-RestartServer
+ ApplicationUUID: 691A2590-F25E-11DD-9995-406635203BE5
+ ConfigFileVersion: 4
+ Database:
+ AutoUpgrade: 1
+ CheckSchema: 1
+ Database: testapp_mason
+ Driver: SQLite
+ Host: localhost
+ Password: ''
+ RecordBaseClass: Jifty::DBI::Record::Cachable
+ User: ''
+ Version: 0.0.1
+ DevelMode: 1
+ L10N:
+ PoDir: share/po
+ LogLevel: FATAL
+ Mailer: Sendmail
+ MailerArgs: []
+
+ Plugins: []
+ PubSub:
+ Backend: Memcached
+ Enable: ~
+ SkipAccessControl: 0
+ TemplateClass: TestApp::Mason::View
+ View:
+ Handlers:
+ - Jifty::View::Mason::Handler
+ Web:
+ BaseURL: http://localhost
+ DataDir: var/mason
+ Globals: []
+
+ MasonConfig:
+ autoflush: 0
+ default_escape_flags: h
+ error_format: text
+ error_mode: fatal
+ Port: 12888
+ ServeStaticFiles: 1
+ StaticRoot: share/web/static
+ TemplateRoot: share/web/templates
Added: jifty/trunk/t/TestApp-RestartServer/t/restart.t
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp-RestartServer/t/restart.t Thu May 7 02:47:15 2009
@@ -0,0 +1,73 @@
+use strict;
+use warnings;
+
+use Test::More tests => 8;
+use File::Spec;
+use Jifty::Test::WWW::Mechanize;
+use FindBin qw($Bin);
+use Cwd;
+my $cwd;
+
+# NOTE: we don't use Jifty's test server just
+# because we want to test Jifty's real server
+
+BEGIN {
+ $cwd = Cwd::cwd();
+ chdir("$Bin/..");
+}
+use Jifty;
+
+my $config_path =
+ File::Spec->catfile( Jifty::Util->app_root, 'etc', 'config.yml' );
+local $/;
+open my $fh, '<', $config_path or die $!;
+my $config = <$fh>;
+like( $config, qr/AdminMode: 1/, 'admin mode in config is enabled' );
+
+my $INC =
+ [ grep { defined } map { File::Spec->rel2abs($_) } grep { !ref } @INC ];
+my @perl = ( $^X, map { "-I$_" } @$INC );
+
+my $pid = fork;
+die 'fork failed' unless defined $pid;
+
+if ($pid) {
+ my $URL = 'http://localhost:12888';
+ my $mech = Jifty::Test::WWW::Mechanize->new;
+ sleep 5;
+ $mech->get_ok($URL);
+ $mech->content_like( qr/pony\.jpg/, 'we have a pony!' );
+ $mech->content_like( qr/Administration mode is enabled/,
+ 'admin mode is enabled' );
+
+ $config =~ s/AdminMode: 1/AdminMode: 0/;
+ like( $config, qr/AdminMode: 0/, 'admin mode in config is off' );
+ write_file( $config_path, $config );
+ system("@perl bin/jifty server --restart");
+ sleep 5;
+ $mech->get_ok($URL);
+ $mech->content_like( qr/pony\.jpg/, 'we still have a pony!' );
+ $mech->content_unlike(
+ qr/Administration mode is enabled/,
+ 'admin mode is gone on page, restart works!',
+ );
+ system("@perl bin/jifty server --stop");
+}
+else {
+ system("@perl bin/jifty server");
+ exit 0;
+}
+
+END {
+ $config =~ s/AdminMode: 0/AdminMode: 1/;
+ write_file( $config_path, $config );
+ chdir $cwd;
+}
+
+sub write_file {
+ my $path = shift;
+ my $content = shift;
+ open my $fh, '>', $path or die $!;
+ print $fh $content;
+ close $fh;
+}
More information about the Jifty-commit
mailing list