~percona-toolkit-dev/percona-toolkit/fix-log-parser-writer-bug-963225

« back to all changes in this revision

Viewing changes to t/lib/CompareResults.t

  • Committer: Daniel Nichter
  • Date: 2011-06-24 17:22:06 UTC
  • Revision ID: daniel@percona.com-20110624172206-c7q4s4ad6r260zz6
Add lib/, t/lib/, and sandbox/.  All modules are updated and passing on MySQL 5.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/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
 
 
14
use Quoter;
 
15
use MySQLDump;
 
16
use TableParser;
 
17
use DSNParser;
 
18
use QueryParser;
 
19
use TableSyncer;
 
20
use TableChecksum;
 
21
use VersionParser;
 
22
use TableSyncGroupBy;
 
23
use MockSyncStream;
 
24
use MockSth;
 
25
use Outfile;
 
26
use RowDiff;
 
27
use ChangeHandler;
 
28
use ReportFormatter;
 
29
use Transformers;
 
30
use Retry;
 
31
use Sandbox;
 
32
use CompareResults;
 
33
use MaatkitTest;
 
34
 
 
35
my $dp  = new DSNParser(opts=>$dsn_opts);
 
36
my $sb  = new Sandbox(basedir => '/tmp', DSNParser => $dp);
 
37
my $dbh1 = $sb->get_dbh_for('master');
 
38
my $dbh2 = $sb->get_dbh_for('slave1');
 
39
 
 
40
if ( !$dbh1 ) {
 
41
   plan skip_all => "Cannot connect to sandbox master";
 
42
}
 
43
elsif ( !$dbh2 ) {
 
44
   plan skip_all => "Cannot connect to sandbox slave";
 
45
}
 
46
else {
 
47
   plan tests => 56;
 
48
}
 
49
 
 
50
$sb->create_dbs($dbh1, ['test']);
 
51
 
 
52
Transformers->import(qw(make_checksum));
 
53
 
 
54
my $vp = new VersionParser();
 
55
my $q  = new Quoter();
 
56
my $qp = new QueryParser();
 
57
my $du = new MySQLDump(cache => 0);
 
58
my $tp = new TableParser(Quoter => $q);
 
59
my $tc = new TableChecksum(Quoter => $q, VersionParser => $vp);
 
60
my $of = new Outfile();
 
61
my $rr = new Retry();
 
62
my $ts = new TableSyncer(
 
63
   Quoter        => $q,
 
64
   VersionParser => $vp,
 
65
   TableChecksum => $tc,
 
66
   Retry         => $rr,
 
67
   MasterSlave   => 1,
 
68
);
 
69
my %modules = (
 
70
   VersionParser => $vp,
 
71
   Quoter        => $q,
 
72
   TableParser   => $tp,
 
73
   TableSyncer   => $ts,
 
74
   QueryParser   => $qp,
 
75
   MySQLDump     => $du,
 
76
   Outfile       => $of,
 
77
);
 
78
 
 
79
my $plugin = new TableSyncGroupBy(Quoter => $q);
 
80
 
 
81
my $cr;
 
82
my $i;
 
83
my $report;
 
84
my @events;
 
85
my $hosts = [
 
86
   { dbh => $dbh1, name => 'master' },
 
87
   { dbh => $dbh2, name => 'slave'  },
 
88
];
 
89
 
 
90
sub proc {
 
91
   my ( $when, %args ) = @_;
 
92
   die "I don't know when $when is"
 
93
      unless $when eq 'before_execute'
 
94
          || $when eq 'execute'
 
95
          || $when eq 'after_execute';
 
96
   for my $i ( 0..$#events ) {
 
97
      $events[$i] = $cr->$when(
 
98
         event    => $events[$i],
 
99
         dbh      => $hosts->[$i]->{dbh},
 
100
         %args,
 
101
      );
 
102
   }
 
103
};
 
104
 
 
105
sub get_id {
 
106
   return make_checksum(@_);
 
107
}
 
108
 
 
109
# #############################################################################
 
110
# Test the checksum method.
 
111
# #############################################################################
 
112
 
 
113
diag(`/tmp/12345/use < $trunk/t/lib/samples/compare-results.sql`);
 
114
 
 
115
$cr = new CompareResults(
 
116
   method     => 'checksum',
 
117
   'base-dir' => '/dev/null',  # not used with checksum method
 
118
   plugins    => [$plugin],
 
119
   get_id     => \&get_id,
 
120
   %modules,
 
121
);
 
122
 
 
123
isa_ok($cr, 'CompareResults');
 
124
 
 
125
@events = (
 
126
   {
 
127
      arg         => 'select * from test.t where i>0',
 
128
      fingerprint => 'select * from test.t where i>?',
 
129
      sampleno    => 1,
 
130
   },
 
131
   {
 
132
      arg         => 'select * from test.t where i>0',
 
133
      fingerprint => 'select * from test.t where i>?',
 
134
      sampleno    => 1,
 
135
   },
 
136
);
 
137
 
 
138
$i = 0;
 
139
MaatkitTest::wait_until(
 
140
   sub {
 
141
      my $r;
 
142
      eval {
 
143
         $r = $dbh1->selectrow_arrayref('SHOW TABLES FROM test LIKE "dropme"');
 
144
      };
 
145
      return 1 if ($r->[0] || '') eq 'dropme';
 
146
      diag('Waiting for CREATE TABLE...') unless $i++;
 
147
      return 0;
 
148
   },
 
149
   0.5,
 
150
   30,
 
151
);
 
152
 
 
153
is_deeply(
 
154
   $dbh1->selectrow_arrayref('SHOW TABLES FROM test LIKE "dropme"'),
 
155
   ['dropme'],
 
156
   'checksum: temp table exists'
 
157
);
 
158
 
 
159
proc('before_execute', db=>'test', 'temp-table'=>'dropme');
 
160
 
 
161
is(
 
162
   $events[0]->{wrapped_query},
 
163
   'CREATE TEMPORARY TABLE `test`.`dropme` AS select * from test.t where i>0',
 
164
   'checksum: before_execute() wraps query in CREATE TEMPORARY TABLE'
 
165
);
 
166
 
 
167
is_deeply(
 
168
   $dbh1->selectall_arrayref('SHOW TABLES FROM test LIKE "dropme"'),
 
169
   [],
 
170
   'checksum: before_execute() drops temp table'
 
171
);
 
172
 
 
173
ok(
 
174
   !exists $events[0]->{Query_time},
 
175
   "checksum: Query_time doesn't exist before execute()"
 
176
);
 
177
 
 
178
proc('execute');
 
179
 
 
180
ok(
 
181
   exists $events[0]->{Query_time},
 
182
   "checksum: Query_time exists after exectue()"
 
183
);
 
184
 
 
185
like(
 
186
   $events[0]->{Query_time},
 
187
   qr/^[\d.]+$/,
 
188
   "checksum: Query_time is a number ($events[0]->{Query_time})"
 
189
);
 
190
 
 
191
is(
 
192
   $events[0]->{wrapped_query},
 
193
   'CREATE TEMPORARY TABLE `test`.`dropme` AS select * from test.t where i>0',
 
194
   "checksum: execute() doesn't unwrap query"
 
195
);
 
196
 
 
197
is_deeply(
 
198
   $dbh1->selectall_arrayref('select * from test.dropme'),
 
199
   [[1],[2],[3]],
 
200
   'checksum: Result set selected into the temp table'
 
201
);
 
202
 
 
203
ok(
 
204
   !exists $events[0]->{row_count},
 
205
   "checksum: row_count doesn't exist before after_execute()"
 
206
);
 
207
 
 
208
ok(
 
209
   !exists $events[0]->{checksum},
 
210
   "checksum: checksum doesn't exist before after_execute()"
 
211
);
 
212
 
 
213
proc('after_execute');
 
214
 
 
215
is(
 
216
   $events[0]->{wrapped_query},
 
217
   'CREATE TEMPORARY TABLE `test`.`dropme` AS select * from test.t where i>0',
 
218
   'checksum: after_execute() left wrapped query'
 
219
);
 
220
 
 
221
is_deeply(
 
222
   $dbh1->selectall_arrayref('SHOW TABLES FROM test LIKE "dropme"'),
 
223
   [],
 
224
   'checksum: after_execute() drops temp table'
 
225
);
 
226
 
 
227
is_deeply(
 
228
   [ $cr->compare(
 
229
      events => \@events,
 
230
      hosts  => $hosts,
 
231
   ) ],
 
232
   [
 
233
      different_row_counts    => 0,
 
234
      different_checksums     => 0,
 
235
      different_column_counts => 0,
 
236
      different_column_types  => 0,
 
237
   ],
 
238
   'checksum: compare, no differences'
 
239
);
 
240
 
 
241
is(
 
242
   $events[0]->{row_count},
 
243
   3,
 
244
   "checksum: correct row_count after after_execute()"
 
245
);
 
246
 
 
247
is(
 
248
   $events[0]->{checksum},
 
249
   '251493421',
 
250
   "checksum: correct checksum after after_execute()"
 
251
);
 
252
 
 
253
ok(
 
254
   !exists $events[0]->{wrapped_query},
 
255
   'checksum: wrapped query removed after compare'
 
256
);
 
257
 
 
258
# Make checksums differ.
 
259
$dbh2->do('update test.t set i = 99 where i=1');
 
260
 
 
261
proc('before_execute', db=>'test', 'temp-table'=>'dropme');
 
262
proc('execute');
 
263
proc('after_execute');
 
264
 
 
265
is_deeply(
 
266
   [ $cr->compare(
 
267
      events => \@events,
 
268
      hosts  => $hosts,
 
269
   ) ],
 
270
   [
 
271
      different_row_counts    => 0,
 
272
      different_checksums     => 1,
 
273
      different_column_counts => 0,
 
274
      different_column_types  => 0,
 
275
   ],
 
276
   'checksum: compare, different checksums' 
 
277
);
 
278
 
 
279
# Make row counts differ, too.
 
280
$dbh2->do('insert into test.t values (4)');
 
281
 
 
282
proc('before_execute', db=>'test', 'temp-table'=>'dropme');
 
283
proc('execute');
 
284
proc('after_execute');
 
285
 
 
286
is_deeply(
 
287
   [ $cr->compare(
 
288
      events => \@events,
 
289
      hosts  => $hosts,
 
290
   ) ],
 
291
   [
 
292
      different_row_counts    => 1,
 
293
      different_checksums     => 1,
 
294
      different_column_counts => 0,
 
295
      different_column_types  => 0,
 
296
   ],
 
297
   'checksum: compare, different checksums and row counts'
 
298
);
 
299
 
 
300
$report = <<EOF;
 
301
# Checksum differences
 
302
# Query ID           master    slave
 
303
# ================== ========= ==========
 
304
# D2D386B840D3BEEA-1 $events[0]->{checksum} $events[1]->{checksum}
 
305
 
 
306
# Row count differences
 
307
# Query ID           master slave
 
308
# ================== ====== =====
 
309
# D2D386B840D3BEEA-1      3     4
 
310
EOF
 
311
 
 
312
is(
 
313
   $cr->report(hosts => $hosts),
 
314
   $report,
 
315
   'checksum: report'
 
316
);
 
317
 
 
318
my %samples = $cr->samples($events[0]->{fingerprint});
 
319
is_deeply(
 
320
   \%samples,
 
321
   {
 
322
      1 => 'select * from test.t where i>0',
 
323
   },
 
324
   'checksum: samples'
 
325
);
 
326
 
 
327
# #############################################################################
 
328
# Test the rows method.
 
329
# #############################################################################
 
330
 
 
331
my $tmpdir = '/tmp/mk-upgrade-res';
 
332
 
 
333
diag(`/tmp/12345/use < $trunk/t/lib/samples/compare-results.sql`);
 
334
diag(`rm -rf $tmpdir; mkdir $tmpdir`);
 
335
 
 
336
$cr = new CompareResults(
 
337
   method     => 'rows',
 
338
   'base-dir' => $tmpdir,
 
339
   plugins    => [$plugin],
 
340
   get_id     => \&get_id,
 
341
   %modules,
 
342
);
 
343
 
 
344
isa_ok($cr, 'CompareResults');
 
345
 
 
346
@events = (
 
347
   {
 
348
      arg => 'select * from test.t',
 
349
      db  => 'test',
 
350
   },
 
351
   {
 
352
      arg => 'select * from test.t',
 
353
      db  => 'test',
 
354
   },
 
355
);
 
356
 
 
357
$i = 0;
 
358
MaatkitTest::wait_until(
 
359
   sub {
 
360
      my $r;
 
361
      eval {
 
362
         $r = $dbh1->selectrow_arrayref('SHOW TABLES FROM test LIKE "dropme"');
 
363
      };
 
364
      return 1 if ($r->[0] || '') eq 'dropme';
 
365
      diag('Waiting for CREATE TABLE...') unless $i++;
 
366
      return 0;
 
367
   },
 
368
   0.5,
 
369
   30,
 
370
);
 
371
 
 
372
is_deeply(
 
373
   $dbh1->selectrow_arrayref('SHOW TABLES FROM test LIKE "dropme"'),
 
374
   ['dropme'],
 
375
   'rows: temp table exists'
 
376
);
 
377
 
 
378
proc('before_execute');
 
379
 
 
380
is(
 
381
   $events[0]->{arg},
 
382
   'select * from test.t',
 
383
   "rows: before_execute() doesn't wrap query and doesn't require tmp table"
 
384
);
 
385
 
 
386
is_deeply(
 
387
   $dbh1->selectrow_arrayref('SHOW TABLES FROM test LIKE "dropme"'),
 
388
   ['dropme'],
 
389
   "rows: before_execute() doesn't drop temp table"
 
390
);
 
391
 
 
392
ok(
 
393
   !exists $events[0]->{Query_time},
 
394
   "rows: Query_time doesn't exist before execute()"
 
395
);
 
396
 
 
397
ok(
 
398
   !exists $events[0]->{results_sth},
 
399
   "rows: results_sth doesn't exist before execute()"
 
400
);
 
401
 
 
402
proc('execute');
 
403
 
 
404
ok(
 
405
   exists $events[0]->{Query_time},
 
406
   "rows: query_time exists after exectue()"
 
407
);
 
408
 
 
409
ok(
 
410
   exists $events[0]->{results_sth},
 
411
   "rows: results_sth exists after exectue()"
 
412
);
 
413
 
 
414
like(
 
415
   $events[0]->{Query_time},
 
416
   qr/^[\d.]+$/,
 
417
   "rows: Query_time is a number ($events[0]->{Query_time})"
 
418
);
 
419
 
 
420
ok(
 
421
   !exists $events[0]->{row_count},
 
422
   "rows: row_count doesn't exist before after_execute()"
 
423
);
 
424
 
 
425
is_deeply(
 
426
   $cr->after_execute(event=>$events[0]),
 
427
   $events[0],
 
428
   "rows: after_execute() doesn't modify the event"
 
429
);
 
430
 
 
431
is_deeply(
 
432
   [ $cr->compare(
 
433
      events => \@events,
 
434
      hosts  => $hosts,
 
435
   ) ],
 
436
   [
 
437
      different_row_counts    => 0,
 
438
      different_column_values => 0,
 
439
      different_column_counts => 0,
 
440
      different_column_types  => 0,
 
441
   ],
 
442
   'rows: compare, no differences'
 
443
);
 
444
 
 
445
is(
 
446
   $events[0]->{row_count},
 
447
   3,
 
448
   "rows: compare() sets row_count"
 
449
);
 
450
 
 
451
is(
 
452
   $events[1]->{row_count},
 
453
   3,
 
454
   "rows: compare() sets row_count"
 
455
);
 
456
 
 
457
# Make the result set differ.
 
458
$dbh2->do('insert into test.t values (5)');
 
459
 
 
460
proc('before_execute');
 
461
proc('execute');
 
462
 
 
463
is_deeply(
 
464
   [ $cr->compare(
 
465
      events => \@events,
 
466
      hosts  => $hosts,
 
467
   ) ],
 
468
   [
 
469
      different_row_counts    => 1,
 
470
      different_column_values => 0,
 
471
      different_column_counts => 0,
 
472
      different_column_types  => 0,
 
473
   ],
 
474
   'rows: compare, different row counts'
 
475
);
 
476
 
 
477
# Use test.t2 and make a column value differ.
 
478
@events = (
 
479
   {
 
480
      arg         => 'select * from test.t2',
 
481
      db          => 'test',
 
482
      fingerprint => 'select * from test.t2',
 
483
      sampleno    => 3,
 
484
   },
 
485
   {
 
486
      arg         => 'select * from test.t2',
 
487
      db          => 'test',
 
488
      fingerprint => 'select * from test.t2',
 
489
      sampleno    => 3,
 
490
   },
 
491
);
 
492
 
 
493
$dbh2->do('update test.t2 set c="should be c" where i=3');
 
494
 
 
495
is_deeply(
 
496
   $dbh2->selectrow_arrayref('select c from test.t2 where i=3'),
 
497
   ['should be c'],
 
498
   'rows: column value is different'
 
499
);
 
500
 
 
501
proc('before_execute');
 
502
proc('execute');
 
503
 
 
504
is_deeply(
 
505
   [ $cr->compare(
 
506
      events => \@events,
 
507
      hosts  => $hosts,
 
508
   ) ],
 
509
   [
 
510
      different_row_counts    => 0,
 
511
      different_column_values => 1,
 
512
      different_column_counts => 0,
 
513
      different_column_types  => 0,
 
514
   ],
 
515
   'rows: compare, different column values'
 
516
);
 
517
 
 
518
is_deeply(
 
519
   $dbh1->selectall_arrayref('show indexes from test.mk_upgrade_left'),
 
520
   [],
 
521
   'Did not add indexes'
 
522
);
 
523
 
 
524
$report = <<EOF;
 
525
# Column value differences
 
526
# Query ID           Column master slave
 
527
# ================== ====== ====== ===========
 
528
# CFC309761E9131C5-3 c      c      should be c
 
529
 
 
530
# Row count differences
 
531
# Query ID           master slave
 
532
# ================== ====== =====
 
533
# B8B721D77EA1FD78-0      3     4
 
534
EOF
 
535
 
 
536
is(
 
537
   $cr->report(hosts => $hosts),
 
538
   $report,
 
539
   'rows: report'
 
540
);
 
541
 
 
542
%samples = $cr->samples($events[0]->{fingerprint});
 
543
is_deeply(
 
544
   \%samples,
 
545
   {
 
546
      3 => 'select * from test.t2'
 
547
   },
 
548
   'rows: samples'
 
549
);
 
550
 
 
551
# #############################################################################
 
552
# Test max-different-rows.
 
553
# #############################################################################
 
554
$cr->reset();
 
555
$dbh2->do('update test.t2 set c="should be a" where i=1');
 
556
$dbh2->do('update test.t2 set c="should be b" where i=2');
 
557
proc('before_execute');
 
558
proc('execute');
 
559
 
 
560
is_deeply(
 
561
   [ $cr->compare(
 
562
      events => \@events,
 
563
      hosts  => $hosts,
 
564
      'max-different-rows' => 1,
 
565
      'add-indexes'        => 1,
 
566
   ) ],
 
567
   [
 
568
      different_row_counts    => 0,
 
569
      different_column_values => 1,
 
570
      different_column_counts => 0,
 
571
      different_column_types  => 0,
 
572
   ],
 
573
   'rows: compare, stop at max-different-rows'
 
574
);
 
575
 
 
576
is_deeply(
 
577
   $dbh1->selectall_arrayref('show indexes from test.mk_upgrade_left'),
 
578
   [['mk_upgrade_left','0','i','1','i','A',undef,undef, undef,'YES','BTREE','']],
 
579
   'Added indexes'
 
580
);
 
581
 
 
582
$report = <<EOF;
 
583
# Column value differences
 
584
# Query ID           Column master slave
 
585
# ================== ====== ====== ===========
 
586
# CFC309761E9131C5-3 c      a      should be a
 
587
EOF
 
588
 
 
589
is(
 
590
   $cr->report(hosts => $hosts),
 
591
   $report,
 
592
   'rows: report max-different-rows'
 
593
);
 
594
 
 
595
# #############################################################################
 
596
# Double check that outfiles have correct contents.
 
597
# #############################################################################
 
598
 
 
599
# This test uses the results from the max-different-rows test above.
 
600
 
 
601
my @outfile = split(/[\t\n]+/, `cat /tmp/mk-upgrade-res/left-outfile.txt`);
 
602
is_deeply(
 
603
        \@outfile,
 
604
        [qw(1 a 2 b 3 c)],
 
605
   'Left outfile'
 
606
);
 
607
 
 
608
@outfile = split(/[\t\n]+/, `cat /tmp/mk-upgrade-res/right-outfile.txt`);
 
609
is_deeply(
 
610
        \@outfile,
 
611
        ['1', 'should be a', '2', 'should be b', '3', 'should be c'],
 
612
   'Right outfile'
 
613
);
 
614
 
 
615
# #############################################################################
 
616
# Test float-precision.
 
617
# #############################################################################
 
618
@events = (
 
619
   {
 
620
      arg         => 'select * from test.t3',
 
621
      db          => 'test',
 
622
      fingerprint => 'select * from test.t3',
 
623
      sampleno    => 3,
 
624
   },
 
625
   {
 
626
      arg         => 'select * from test.t3',
 
627
      db          => 'test',
 
628
      fingerprint => 'select * from test.t3',
 
629
      sampleno    => 3,
 
630
   },
 
631
);
 
632
 
 
633
$cr->reset();
 
634
$dbh2->do('update test.t3 set f=1.12346 where 1');
 
635
proc('before_execute');
 
636
proc('execute');
 
637
 
 
638
is_deeply(
 
639
   [ $cr->compare(
 
640
      events => \@events,
 
641
      hosts  => $hosts,
 
642
   ) ],
 
643
   [
 
644
      different_row_counts    => 0,
 
645
      different_column_values => 1,
 
646
      different_column_counts => 0,
 
647
      different_column_types  => 0,
 
648
   ],
 
649
   'rows: compare, different without float-precision'
 
650
);
 
651
 
 
652
proc('before_execute');
 
653
proc('execute');
 
654
 
 
655
is_deeply(
 
656
   [ $cr->compare(
 
657
      events => \@events,
 
658
      hosts  => $hosts,
 
659
      'float-precision' => 3
 
660
   ) ],
 
661
   [
 
662
      different_row_counts    => 0,
 
663
      different_column_values => 0,
 
664
      different_column_counts => 0,
 
665
      different_column_types  => 0,
 
666
   ],
 
667
   'rows: compare, not different with float-precision'
 
668
);
 
669
 
 
670
# #############################################################################
 
671
# Test when left has more rows than right.
 
672
# #############################################################################
 
673
$cr->reset();
 
674
$dbh1->do('update test.t3 set f=0 where 1');
 
675
$dbh1->do('SET SQL_LOG_BIN=0');
 
676
$dbh1->do('insert into test.t3 values (2.0),(3.0)');
 
677
$dbh1->do('SET SQL_LOG_BIN=1');
 
678
 
 
679
my $left_n_rows = $dbh1->selectcol_arrayref('select count(*) from test.t3')->[0];
 
680
my $right_n_rows = $dbh2->selectcol_arrayref('select count(*) from test.t3')->[0];
 
681
ok(
 
682
   $left_n_rows == 3 && $right_n_rows == 1,
 
683
   'Left has extra rows'
 
684
);
 
685
 
 
686
proc('before_execute');
 
687
proc('execute');
 
688
 
 
689
is_deeply(
 
690
   [ $cr->compare(
 
691
      events => \@events,
 
692
      hosts  => $hosts,
 
693
      'float-precision' => 3
 
694
   ) ],
 
695
   [
 
696
      different_row_counts    => 1,
 
697
      different_column_values => 0,
 
698
      different_column_counts => 0,
 
699
      different_column_types  => 0,
 
700
   ],
 
701
   'rows: compare, left with more rows'
 
702
);
 
703
 
 
704
$report = <<EOF;
 
705
# Row count differences
 
706
# Query ID           master slave
 
707
# ================== ====== =====
 
708
# D56E6FABA26D1F1C-3      3     1
 
709
EOF
 
710
 
 
711
is(
 
712
   $cr->report(hosts => $hosts),
 
713
   $report,
 
714
   'rows: report, left with more rows'
 
715
);
 
716
 
 
717
# #############################################################################
 
718
# Try to compare without having done the actions.
 
719
# #############################################################################
 
720
@events = (
 
721
   {
 
722
      arg => 'select * from test.t',
 
723
      db  => 'test',
 
724
   },
 
725
   {
 
726
      arg => 'select * from test.t',
 
727
      db  => 'test',
 
728
   },
 
729
);
 
730
 
 
731
$cr = new CompareResults(
 
732
   method     => 'checksum',
 
733
   'base-dir' => '/dev/null',  # not used with checksum method
 
734
   plugins    => [$plugin],
 
735
   get_id     => \&get_id,
 
736
   %modules,
 
737
);
 
738
 
 
739
my @diffs;
 
740
eval {
 
741
   @diffs = $cr->compare(events => \@events, hosts => $hosts);
 
742
};
 
743
 
 
744
is(
 
745
   $EVAL_ERROR,
 
746
   '',
 
747
   "compare() checksums without actions doesn't die"
 
748
);
 
749
 
 
750
is_deeply(
 
751
   \@diffs,
 
752
   [
 
753
      different_row_counts    => 0,
 
754
      different_checksums     => 0,
 
755
      different_column_counts => 0,
 
756
      different_column_types  => 0,
 
757
   ],
 
758
   'No differences after bad compare()'
 
759
);
 
760
 
 
761
$cr = new CompareResults(
 
762
   method     => 'rows',
 
763
   'base-dir' => $tmpdir,
 
764
   plugins    => [$plugin],
 
765
   get_id     => \&get_id,
 
766
   %modules,
 
767
);
 
768
 
 
769
eval {
 
770
   @diffs = $cr->compare(events => \@events, hosts => $hosts);
 
771
};
 
772
 
 
773
is(
 
774
   $EVAL_ERROR,
 
775
   '',
 
776
   "compare() rows without actions doesn't die"
 
777
);
 
778
 
 
779
is_deeply(
 
780
   \@diffs,
 
781
   [
 
782
      different_row_counts    => 0,
 
783
      different_column_values => 0,
 
784
      different_column_counts => 0,
 
785
      different_column_types  => 0,
 
786
   ],
 
787
   'No differences after bad compare()'
 
788
);
 
789
 
 
790
# #############################################################################
 
791
# Done.
 
792
# #############################################################################
 
793
my $output = '';
 
794
{
 
795
   local *STDERR;
 
796
   open STDERR, '>', \$output;
 
797
   $cr->_d('Complete test coverage');
 
798
}
 
799
like(
 
800
   $output,
 
801
   qr/Complete test coverage/,
 
802
   '_d() works'
 
803
);
 
804
diag(`rm -rf $tmpdir`);
 
805
diag(`rm -rf /tmp/*outfile.txt`);
 
806
$sb->wipe_clean($dbh1);
 
807
exit;