X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Ft%2Ffts%2Findexed_mysql.t;h=672b220723d4b9478922fc5807d6aef08663c65c;hb=c82e10e2a7af8039962b3f2bd8df4050977c279c;hp=c124ff8f8cd15c0a1dd6a23fb98d7e29e4a97992;hpb=3d0a1bb06b895c5be6e3f0517d355442a6b1e125;p=freeside.git diff --git a/rt/t/fts/indexed_mysql.t b/rt/t/fts/indexed_mysql.t index c124ff8f8..672b22072 100644 --- a/rt/t/fts/indexed_mysql.t +++ b/rt/t/fts/indexed_mysql.t @@ -4,18 +4,8 @@ use warnings; use RT::Test tests => undef; plan skip_all => 'Not mysql' unless RT->Config->Get('DatabaseType') eq 'mysql'; -plan skip_all => "No SphinxSE in mysql" unless $RT::Handle->CheckSphinxSE; -my %sphinx; -$sphinx{'searchd'} = RT::Test->find_executable('searchd'); -$sphinx{'indexer'} = RT::Test->find_executable('indexer'); - -plan skip_all => "No searchd and indexer under PATH" - unless $sphinx{'searchd'} && $sphinx{'indexer'}; - -plan tests => 15; - -RT->Config->Set( FullTextSearch => Enable => 1, Indexed => 1, Table => 'AttachmentsIndex', MaxMatches => 1000 ); +RT->Config->Set( FullTextSearch => Enable => 1, Indexed => 1, Table => 'AttachmentsIndex' ); setup_indexing(); @@ -24,59 +14,22 @@ ok $q && $q->id, 'loaded or created queue'; my $queue = $q->Name; sub setup_indexing { - # Since we're not running a webserver in this test, use the - # known-safe port we determined at test setup - my $port = $RT::Test::port; - my ($exit_code, $output) = RT::Test->run_and_capture( + my %args = ( 'no-ask' => 1, command => $RT::SbinPath .'/rt-setup-fulltext-index', dba => $ENV{'RT_DBA_USER'}, 'dba-password' => $ENV{'RT_DBA_PASSWORD'}, - url => "sphinx://localhost:$port/rt", ); - ok(!$exit_code, "setted up index"); - diag "output: $output" if $ENV{'TEST_VERBOSE'}; - - my $tmp = $sphinx{'directory'} = File::Spec->catdir( RT::Test->temp_directory, 'sphinx' ); - mkdir $tmp; - - my $sphinx_conf = $output; - $sphinx_conf =~ s/.*?source rt {/source rt {/ms; - $sphinx_conf =~ s{\Q$RT::VarPath\E/sphinx/}{$tmp/}g; - - $sphinx{'config'} = File::Spec->catfile( $tmp, 'sphinx.conf' ); - { - open my $fh, ">", $sphinx{'config'}; - print $fh $sphinx_conf; - close $fh; - } - - sync_index(); - - { - my ($exit_code, $output) = RT::Test->run_and_capture( - command => $sphinx{'searchd'}, - config => $sphinx{'config'}, - ); - ok(!$exit_code, "setted up index") or diag "output: $output"; - $sphinx{'started'} = 1 if !$exit_code; - } + my ($exit_code, $output) = RT::Test->run_and_capture( %args ); + ok(!$exit_code, "setted up index") or diag "output: $output"; } sub sync_index { - local $SIG{'CHLD'} = 'DEFAULT'; - local $SIG{'PIPE'} = 'DEFAULT'; - open my $fh, '-|', $sphinx{'indexer'}, '--all', - '--config' => $sphinx{'config'}, - $sphinx{'started'}? ('--rotate') : (), - ; - my $output = <$fh>; - close $fh; - my $exit_code = $?>>8; - ok(!$exit_code, "indexed") or diag "output: $output"; - - # We may need to wait a second for searchd to pick up the changes - sleep 1; + my %args = ( + command => $RT::SbinPath .'/rt-fulltext-indexer', + ); + my ($exit_code, $output) = RT::Test->run_and_capture( %args ); + ok(!$exit_code, "setted up index") or diag "output: $output"; } sub run_tests { @@ -113,21 +66,18 @@ sub run_test { @tickets = RT::Test->create_tickets( { Queue => $q->id }, - { Subject => 'book', Content => 'book' }, - { Subject => 'bar', Content => 'bar' }, + { Subject => 'first', Content => 'english' }, + { Subject => 'second', Content => 'french' }, + { Subject => 'third', Content => 'spanish' }, + { Subject => 'fourth', Content => 'german' }, ); sync_index(); run_tests( - "Content LIKE 'book'" => { book => 1, bar => 0 }, - "Content LIKE 'bar'" => { book => 0, bar => 1 }, + "Content LIKE 'english'" => { first => 1, second => 0, third => 0, fourth => 0 }, + "Content LIKE 'french'" => { first => 0, second => 1, third => 0, fourth => 0 }, ); -END { - my $Test = RT::Test->builder; - return if $Test->{Original_Pid} != $$; - return unless $sphinx{'started'}; +@tickets = (); - my $pid = int RT::Test->file_content([$sphinx{'directory'}, 'searchd.pid']); - kill TERM => $pid if $pid; -} +done_testing;