Skip to content

Commit

Permalink
Increase precision of test_wp_query_failed_ping to avoid racy failu…
Browse files Browse the repository at this point in the history
…res (#332)

* Truly noop the connection details, to avoid accidental reconnection.
* Precisely test the post returned by the query.
* Increase uniqueness of search string.
* Closes #274
  • Loading branch information
danielbachhuber authored and ataylorme committed Oct 9, 2017
1 parent 504f612 commit 3a8ea27
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
3 changes: 3 additions & 0 deletions includes/class-solrpower-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ function get_solr() {
$solarium_config['endpoint']['localhost']['port'] &&
$solarium_config['endpoint']['localhost']['path'] )
) {
$host = isset( $solarium_config['endpoint']['localhost']['host'] ) ? $solarium_config['endpoint']['localhost']['host'] : '';
$port = isset( $solarium_config['endpoint']['localhost']['port'] ) ? $solarium_config['endpoint']['localhost']['port'] : '';
$path = isset( $solarium_config['endpoint']['localhost']['path'] ) ? $solarium_config['endpoint']['localhost']['path'] : '';
syslog( LOG_ERR, "host, port or path are empty, host:$host, port:$port, path:$path" );

return null;
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/class-solr-test-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,4 @@ function __setup_custom_fields() {
update_post_meta( $p_id, 'other_field', 'other_value' );
SolrPower_Sync::get_instance()->load_all_posts( 0, 'post', 100, false );
}
}
}
40 changes: 22 additions & 18 deletions tests/phpunit/wp_query/test-wp-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,24 +141,28 @@ function test_wp_query_by_post_type_arr() {
}

function test_wp_query_failed_ping() {
$this->__create_test_post();
$args = array(
's' => 'solr'
);
SolrPower_Api::get_instance()->ping=false;
$query = new WP_Query( $args );
$this->assertEquals( $query->post_count, 1 );
$this->assertEquals( $query->found_posts, 1 );
while ( $query->have_posts() ) {
$query->the_post();

global $post;

$this->assertFalse( isset($post->solr) );
}

wp_reset_postdata();
SolrPower_Api::get_instance()->ping=true;
$this->__create_test_post( 'post', 'Query Failed Ping' );
$noop_connection = function() {
return array(
'endpoint' => array(
'localhost' => array(
'host' => '',
'port' => '',
'path' => '',
)
),
);
};
add_filter( 's4wp_connection_options', $noop_connection );
SolrPower_Api::get_instance()->solr = null;
SolrPower_Api::get_instance()->ping = false;
$query = new WP_Query( array(
's' => 'Query Failed Ping',
) );
$this->assertEquals( 1, $query->post_count );
$this->assertEquals( 1, $query->found_posts );
$this->assertFalse( isset( $query->posts[0]->solr ) );
remove_filter( 's4wp_connection_options', $noop_connection );
}

public function test_wp_query_search_filter_post_type() {
Expand Down

0 comments on commit 3a8ea27

Please sign in to comment.