~percona-toolkit-dev/percona-toolkit/2.2

« back to all changes in this revision

Viewing changes to t/pt-upgrade/run_time.t

  • Committer: Daniel Nichter
  • Date: 2013-03-12 15:21:13 UTC
  • mfrom: (507.1.37 pt-upgrade-2.2)
  • Revision ID: daniel@percona.com-20130312152113-jfkrxi3p8ca84oin
Merge pt-upgrade-2.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env perl
 
2
 
 
3
BEGIN {
 
4
   die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
 
5
      unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
 
6
   unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
 
7
};
 
8
 
 
9
use strict;
 
10
use warnings FATAL => 'all';
 
11
use English qw(-no_match_vars);
 
12
use Test::More;
 
13
use Time::HiRes qw(time);
 
14
use File::Temp qw(tempdir);
 
15
 
 
16
$ENV{PERCONA_TOOLKIT_TEST_USE_DSN_NAMES} = 1;
 
17
 
 
18
use PerconaTest;
 
19
use Sandbox;
 
20
require "$trunk/bin/pt-upgrade";
 
21
 
 
22
# This runs immediately if the server is already running, else it starts it.
 
23
diag(`$trunk/sandbox/start-sandbox master 12348 >/dev/null`);
 
24
 
 
25
my $dp = new DSNParser(opts=>$dsn_opts);
 
26
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
 
27
my $dbh1 = $sb->get_dbh_for('host1');
 
28
my $dbh2 = $sb->get_dbh_for('host2');
 
29
 
 
30
if ( !$dbh1 ) {
 
31
   plan skip_all => 'Cannot connect to sandbox host1'; 
 
32
}
 
33
elsif ( !$dbh2 ) {
 
34
   plan skip_all => 'Cannot connect to sandbox host2';
 
35
}
 
36
 
 
37
my $host1_dsn   = $sb->dsn_for('host1');
 
38
my $host2_dsn   = $sb->dsn_for('host2');
 
39
my $tmpdir      = tempdir("/tmp/pt-upgrade.$PID.XXXXXX", CLEANUP => 1);
 
40
my $samples     = "$trunk/t/pt-upgrade/samples";
 
41
my $exit_status = 0;
 
42
my $output;
 
43
 
 
44
# #############################################################################
 
45
# Executing queries
 
46
# #############################################################################
 
47
 
 
48
my $t0 = time;
 
49
 
 
50
$output = output(
 
51
   sub {
 
52
      $exit_status = pt_upgrade::main($host1_dsn, $host2_dsn,
 
53
         "$samples/slow_slow.log", qw(--run-time 3),
 
54
         '--progress', 'time,1',
 
55
   )},
 
56
   stderr => 1,
 
57
);
 
58
 
 
59
my $t = time - $t0;
 
60
 
 
61
ok(
 
62
   $t >= 3 && $t <= 6,
 
63
   "Exec queries: ran for roughly --run-time seconds"
 
64
) or diag($output, 'Actual run time:', $t);
 
65
 
 
66
# Exit status 8 = --run-time expired (an no other errors/problems)
 
67
is(
 
68
   $exit_status,
 
69
   8,
 
70
   "Exec queries: exit status 8"
 
71
) or diag($output);
 
72
 
 
73
like(
 
74
   $output,
 
75
   qr/slow_slow.log.+?remain/,
 
76
   "Exec queries: --progress"
 
77
);
 
78
 
 
79
# #############################################################################
 
80
# Saving results
 
81
# #############################################################################
 
82
 
 
83
$t0 = time;
 
84
 
 
85
$output = output(
 
86
   sub {
 
87
      $exit_status = pt_upgrade::main($host1_dsn,
 
88
         '--save-results', $tmpdir,
 
89
         "$samples/slow_slow.log", qw(--run-time 3),
 
90
         '--progress', 'time,1',
 
91
   )},
 
92
   stderr => 1,
 
93
);
 
94
 
 
95
$t = time - $t0;
 
96
 
 
97
ok(
 
98
   $t >= 3 && $t <= 6,
 
99
   "Save results: ran for roughly --run-time seconds"
 
100
) or diag($output, 'Actual run time:', $t);
 
101
 
 
102
# Exit status 8 = --run-time expired (an no other errors/problems)
 
103
is(
 
104
   $exit_status,
 
105
   8,
 
106
   "Save results: exit status 8"
 
107
) or diag($output);
 
108
 
 
109
like(
 
110
   $output,
 
111
   qr/slow_slow.log.+?remain/,
 
112
   "Save results: --progress"
 
113
);
 
114
 
 
115
# #############################################################################
 
116
# Done.
 
117
# #############################################################################
 
118
#$sb->wipe_clean($dbh2);
 
119
$sb->wipe_clean($dbh1);
 
120
diag(`$trunk/sandbox/stop-sandbox 12348 >/dev/null`);
 
121
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
 
122
done_testing;