#!perl
use Cassandane::Tiny;

# search_maxtime of 0 is treated as no timeout (see cmdtime_checksearch)
# so we need something small.
# (Don't use a negative timeout, as that seems like a bug we should fix)

sub test_search_sort_thread_maxtime
    :needs_search_xapian :SearchMaxtime(1.e-18)
    ($self)
{
    my $talk = $self->{store}->get_client();

    $self->make_message("needle") || die;
    $talk->select('INBOX');

    # With search_maxtime set to nothing, any search times out immediately
    my $crit = 'SUBJECT a';

    xlog "SEARCH must report the timeout";
    my $uids = $talk->search(\$crit);
    $self->assert_null($uids);
    $self->assert_matches(qr/taking too long/i, $talk->get_last_error());

    xlog "SORT must report the timeout";
    $uids = $talk->sort('(ARRIVAL)', 'UTF-8', \$crit);
    $self->assert_null($uids);
    $self->assert_matches(qr/taking too long/i, $talk->get_last_error());

    xlog "THREAD must report the timeout";
    $uids = $talk->thread('ORDEREDSUBJECT', 'UTF-8', \$crit);
    $self->assert_null($uids);
    $self->assert_matches(qr/taking too long/i, $talk->get_last_error());
}
