Fix result-set leak.
[irspy-moved-to-github.git] / lib / ZOOM / IRSpy / Test / Search / Explain.pm
1 # $Id: Explain.pm,v 1.7 2007-03-15 11:41:24 mike Exp $
2
3 # See the "Main" test package for documentation
4
5 package ZOOM::IRSpy::Test::Search::Explain;
6
7 use 5.008;
8 use strict;
9 use warnings;
10
11 use ZOOM::IRSpy::Test;
12 our @ISA = qw(ZOOM::IRSpy::Test);
13
14
15 sub start {
16     my $class = shift();
17     my($conn) = @_;
18     my @explain = qw(CategoryList TargetInfo DatabaseInfo SchemaInfo TagSetInfo
19                      RecordSyntaxInfo AttributeSetInfo TermListInfo
20                      ExtendedServicesInfo AttributeDetails TermListDetails
21                      ElementSetDetails RetrivalRecordDetails SortDetails
22                      Processing VariantSetInfo UnitSet);
23
24     foreach my $category (@explain) {
25         $conn->irspy_search_pqf('@attr exp-1 1=1 ' . $category,
26                                 {'category' => $category},
27                                 { databaseName => 'IR-Explain-1' },
28                                 ZOOM::Event::ZEND, \&found,
29                                 exception => \&error);
30     }
31 }
32
33
34 sub found {
35     my($conn, $task, $test_args, $event) = @_;
36     my $category = $test_args->{'category'};
37
38     my $n = $task->{rs}->size();
39     $task->{rs}->destroy();
40     my $ok = ($n > 0);
41     $conn->log("irspy_test", "Explain category ", $category, " gave ", $n,
42                " hit(s).");
43
44     update($conn, $category, $ok);
45
46     return ZOOM::IRSpy::Status::TASK_DONE;
47 }
48
49
50 sub error {
51     my($conn, $task, $test_args, $exception) = @_;
52     my $category = $test_args->{'category'};
53
54     $task->{rs}->destroy();
55     $conn->log("irspy_test", "Explain category lookup failed: ", $exception);
56     update($conn, $category, 0);
57
58     return ZOOM::IRSpy::Status::TEST_BAD
59         if ($exception->code() == 109 || # Database unavailable
60             $exception->code() == 235); # Database does not exist
61
62     return ZOOM::IRSpy::Status::TASK_DONE;
63 }
64
65
66 sub update {
67     my ($conn, $category, $ok) = @_;
68     $conn->record()->store_result('explain', 'category'  => $category,
69                                              'ok'        => $ok);
70 }
71
72 1;