You are missing $locations->the_post()
in your loop:
if ( $locations -> have_posts() ) {
while ( $locations -> have_posts() ) {
$locations->the_post(); // Needed
echo 'yes';
}
}
One of the things this function does is advance $locations
to the next post. Without it $locations->have_posts()
will just repeat infinitely for the first post.