#!perl
use Cassandane::Tiny;

sub test_references_chain_long ($self)
{
    xlog $self, "test THREAD with a linear chain of more than 20 inter-message references";
    my $talk = $self->{store}->get_client();

    xlog $self, "append some messages";
    my $sub = 'Hello World!';
    my %exp;
    my @refs;
    my @expthreads;
    my $N = 25;
    for (1..$N)
    {
        my $msg;
        if (scalar @refs)
        {
            $msg = $self->make_message("Re: " . $sub,
                                       references => [ @refs ]);
        }
        else
        {
            $msg = $self->make_message($sub);
        }
        push(@refs, $msg->{'headers_by_name'}{'message-id'}[0]);
        push(@expthreads, $msg->uid);
        $exp{$_} = $msg;
    }
    xlog $self, "check the messages got there";
    $self->check_messages(\%exp, ( keyed_on => 'uid' ));

    xlog $self, "All messages should still be threaded";
    my $res = $talk->thread('REFERENCES', 'US-ASCII', 'ALL');
    $self->assert_cmp_deeply([[ @expthreads ]], $res);
}
