1 # See the "Main" test package for documentation
3 ### Too much common code with OPAC.pm: need to refactor
5 package ZOOM::IRSpy::Test::Record::PiggyBack;
11 use ZOOM::IRSpy::Test;
12 our @ISA = qw(ZOOM::IRSpy::Test);
16 "\@attr 1=4 computer",
17 "\@attr 1=44 mineral", # Smithsonian doesn't support AP 4!
18 "\@attr 1=1016 water", # Connector Framework only does 1016
19 ### We can add more queries here
22 # We'd like to use this temporary-options hash to set
23 # preferredRecordSyntax, as well But that doesn't work because the
24 # same value needs to be in force later on when we make the
25 # record_immediate() call, otherwise it misses its cache.
29 # preferredRecordSyntax => "usmarc"
36 ### It would be better to consult previous tests to find a working RS
37 $conn->option(preferredRecordSyntax => "usmarc");
38 $conn->irspy_search_pqf($queries[0], { queryindex => 0 }, \%options,
39 ZOOM::Event::ZEND, \&completed_search,
40 exception => \&completed_search);
44 sub completed_search {
45 my($conn, $task, $udata, $event) = @_;
47 if ($event->isa("ZOOM::Exception") && $event->code() == 1005) {
48 $conn->log("irspy_test", "Piggyback searching not supported");
49 $conn->record()->store_result('piggyback', 'ok' => 0);
50 return ZOOM::IRSpy::Status::TEST_BAD;
53 my $n = $task->{rs}->size();
54 $conn->log("irspy_test", "Piggyback test search (", $task->render_query(), ") ",
55 ref $event && $event->isa("ZOOM::Exception") ?
56 "failed: $event" : "found $n records (event=$event)");
58 # remember how often a target record hit a timeout
59 if (ref $event && $event->isa("ZOOM::Exception")) {
60 if ($event =~ /Timeout/i) {
61 $conn->record->zoom_error->{TIMEOUT}++;
62 $conn->log("irspy_test", "Increase timeout error counter to: " .
63 $conn->record->zoom_error->{TIMEOUT});
68 $task->{rs}->destroy();
69 my $qindex = $udata->{queryindex}+1;
70 my $q = $queries[$qindex];
71 return ZOOM::IRSpy::Status::TEST_SKIPPED
72 if !defined $q || $conn->record->zoom_error->{TIMEOUT} >= $ZOOM::IRSpy::max_timeout_errors;
74 $conn->log("irspy_test", "Trying another search ...");
75 $conn->irspy_search_pqf($queries[$qindex], { queryindex => $qindex }, \%options,
76 ZOOM::Event::ZEND, \&completed_search,
77 exception => \&completed_search);
78 return ZOOM::IRSpy::Status::TASK_DONE;
81 # We have a result-set of three of more records, and we requested
82 # that those records be included in the Search Response using
83 # piggybacking. Was it done?
84 my $rec = $task->{rs}->record_immediate(2);
85 my $ok = defined $rec && $rec->error() == 0;
87 $task->{rs}->destroy();
88 $conn->record()->store_result('piggyback', 'ok' => $ok);
89 return $ok ? ZOOM::IRSpy::Status::TEST_GOOD : ZOOM::IRSpy::Status::TEST_BAD;